Problem with simplify function used with matrices

21 views (last 30 days)
Hello, I am trying to simplify this matrix, but I can't see any changes. I have tried with the same function many times, yet it won't help me obtain a simplified version of the matrix:
clear all;
syms t1 d2 a3 t3
A10 = [cos(t1), -sin(t1), 0, 0;
sin(t1), cos(t1), 0, 0;
0, 0, 1, 0;
0, 0, 0, 1];
A21 = [1, 0, 0, 0;
0, 0, 1, 0;
0, -1, 0, d2;
0, 0, 0, 1];
A32 = [cos(t3), 0, sin(t3), a3*cos(t3);
sin(t3), 0, -cos(t3), a3*sin(t3);
0, 1, 0, 0;
0, 0, 0, 1];
A30 = A10*A21*A32
A30s = simplify(A30)
This is my output:
A30 =
[cos(t1)*cos(t3), -sin(t1), cos(t1)*sin(t3), a3*cos(t1)*cos(t3)]
[cos(t3)*sin(t1), cos(t1), sin(t1)*sin(t3), a3*cos(t3)*sin(t1)]
[ -sin(t3), 0, cos(t3), d2 - a3*sin(t3)]
[ 0, 0, 0, 1]
A30s =
[cos(t1)*cos(t3), -sin(t1), cos(t1)*sin(t3), a3*cos(t1)*cos(t3)]
[cos(t3)*sin(t1), cos(t1), sin(t1)*sin(t3), a3*cos(t3)*sin(t1)]
[ -sin(t3), 0, cos(t3), d2 - a3*sin(t3)]
[ 0, 0, 0, 1]
As you can see the matrices look exactly the same.
  2 Comments
John D'Errico
John D'Errico on 30 Nov 2020
And why is it you think something simpler would be appropriate? What did you expect to see that is different from what you got?
Giulia Di Fede
Giulia Di Fede on 30 Nov 2020
Maybe I needed to add more background, excuse me.
I posted only a part of the code as then it becomes redundant, in fact I need to simplify a much bigger matrix:
T80 = A10*A21*A32*A43*A54*A65*A76*A87;
T80s = simplify(T80);
I am expecting, for example, this kind of simplification:
M =
[cos(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)) - sin(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)), - cos(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)) - sin(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)), 0, a1*cos(t1) + a2*cos(t1)*cos(t2) - a2*sin(t1)*sin(t2)]
[cos(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)) + sin(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)), cos(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)) - sin(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)), 0, a1*sin(t1) + a2*cos(t1)*sin(t2) + a2*cos(t2)*sin(t1)]
[ 0, 0, 1, d3]
[ 0, 0, 0, 1]
Ms =
[cos(t1 + t2 + t4), -sin(t1 + t2 + t4), 0, a2*cos(t1 + t2) + a1*cos(t1)]
[sin(t1 + t2 + t4), cos(t1 + t2 + t4), 0, a2*sin(t1 + t2) + a1*sin(t1)]
[ 0, 0, 1, d3]
[ 0, 0, 0, 1]
But in this case, there are way less multiplications, as the matrix could be A = M1*M2*M3*M4

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 30 Nov 2020
Edited: Ameer Hamza on 30 Nov 2020
MATLAB's symbolic toolbox is not perfect (perhaps it is impossible to make a perfect symbolic engine), and every year they make some improvements. This seems one such case. Also, "simplification" is not a well defined idea. The tips section of simplify() documentation mentions: "Simplification of mathematical expression is not a clearly defined subject. There is no universal idea as to which form of an expression is simplest. The form of a mathematical expression that is simplest for one problem might be complicated or even unsuitable for another problem."
Are you using an older release of MATLAB? In R2020b, it is simplified as you described in your comment
syms t1 t2 t3 t4 a1 a2 d3
M = [
cos(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)) - sin(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)), - cos(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)) - sin(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)), 0, a1*cos(t1) + a2*cos(t1)*cos(t2) - a2*sin(t1)*sin(t2)
cos(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)) + sin(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)), cos(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)) - sin(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)), 0, a1*sin(t1) + a2*cos(t1)*sin(t2) + a2*cos(t2)*sin(t1)
0, 0, 1, d3
0, 0, 0, 1];
M_simplify = simplify(M)
Result
>> M_simplify
M_simplify =
[cos(t1 + t2 + t4), -sin(t1 + t2 + t4), 0, a2*cos(t1 + t2) + a1*cos(t1)]
[sin(t1 + t2 + t4), cos(t1 + t2 + t4), 0, a2*sin(t1 + t2) + a1*sin(t1)]
[ 0, 0, 1, d3]
[ 0, 0, 0, 1]
You may experiment with following option if you are using an older release of MATLAB
M_simplify = simplify(M, 'Seconds', 10); % specify maximum number of seconds MATLAB spent on simplification
  3 Comments
Ameer Hamza
Ameer Hamza on 30 Nov 2020
But why do you expect it to be simplified to a simple form? It might be the case that there are no factors that can be combined to write a shorter expression.

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!