Search code examples
matlabsymbolic-math

Symbolic constants in MATLAB


I am playing around with homogeneous transformations in MATLAB. I got a Transformation which looks like this

>> T01

T01 =

[ cos(phi1), -sin(phi1), 0, 0]
[ sin(phi1),  cos(phi1), 0, 0]
[         0,          0, 1, 0]
[         0,          0, 0, 1]

A simple rotation around the z axis. I used phi1=sym('phi1'). Now if i calculate the inverse T01 * inv(T01) MATLAB is not displaying the Identity matrix but rather a matrix with huge expressions. If i use any explicit values for phi1, it works. How can i make MATLAB cancel out symbolic values?

Thanks

EDIT: Interestingly, for some operations it does cancel out symbolic constants:

>> (phi1*phi2)/phi1

ans =

phi2

Solution

  • Use simplify

    >> simplify(T01*inv(T01))
    
    
    ans =
    
    [ 1, 0, 0, 0]
    [ 0, 1, 0, 0]
    [ 0, 0, 1, 0]
    [ 0, 0, 0, 1]
    

    Probably for performance reasons, only very simple simplification rules are applied automatically in each step.