Display rotation matrix with s1, c1, etc. in place of sind(theta1), cosd(theta1), etc. respectively.

2 views (last 30 days)
How can I easily display rotation matrix results by s1, c1, etc. in place of sind(theta1), cosd(theta1), etc. respectively. [theta1, theta2 are defined by syms]

Accepted Answer

Paul
Paul on 11 Apr 2021
Use subs:
>> doc subs
>> syms theta1 s1 c1
>> A=[cos(theta1) sin(theta1);-sin(theta1) cos(theta1)]
A =
[ cos(theta1), sin(theta1)]
[ -sin(theta1), cos(theta1)]
>> subs(subs(A,cos(theta1),c1),sin(theta1),s1)
ans =
[ c1, s1]
[ -s1, c1]
  3 Comments
Paul
Paul on 11 Apr 2021
Use subs() combined with sym() if the variables are named theta1, theta2, etc.
>> syms theta1 theta2 theta3
>> A=[cos(theta1) sin(theta1);-sin(theta1) cos(theta1)];
>> B=[cos(theta2) sin(theta2);-sin(theta2) cos(theta2)];
>> C=[cos(theta3) sin(theta3);-sin(theta3) cos(theta3)];
>> D=A*B*C
D =
[ cos(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)) - sin(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)), cos(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)) + sin(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2))]
[ - cos(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)) - sin(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)), cos(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)) - sin(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1))]
>> subs(D,[cos(sym('theta',[1 3])) sin(sym('theta',[1 3]))],[sym('c',[1 3]) sym('s',[1 3])])
ans =
[ c3*(c1*c2 - s1*s2) - s3*(c1*s2 + c2*s1), c3*(c1*s2 + c2*s1) + s3*(c1*c2 - s1*s2)]
[ - c3*(c1*s2 + c2*s1) - s3*(c1*c2 - s1*s2), c3*(c1*c2 - s1*s2) - s3*(c1*s2 + c2*s1)]

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!