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

1 次查看（过去 30 天）
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]

### 采纳的回答

Paul 2021-4-11
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 个评论显示 1更早的评论隐藏 1更早的评论
Paul 2021-4-11
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 2021-4-11
Fantastic! this is a great solution. Thank you very much.

### 类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by