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

1 vue (au cours des 30 derniers jours)
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]

Réponse acceptée

Paul
Paul le 11 Avr 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 commentaires
Paul
Paul le 11 Avr 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)]
Sourabh Karmakar
Sourabh Karmakar le 11 Avr 2021
Fantastic! this is a great solution. Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by