Symbolic substitution in matrices

조회 수: 3 (최근 30일)
Sina
Sina 2013년 10월 16일
댓글: Sina 2013년 10월 16일
I was writing this symbolic matrix in matlab, and I wanted to substitute values for "x" in sin(x) and cos(x), but it didn't give me the actual value of the sin(x), only an expression like: sin(30) in the matrix, and also it didn't compute divisions and all other computations. I couldn't find the problem with the code. Please guide me to find the right way to write this code. example of the expression in the answer, after substitution: (3^(1/2)*(cos(pi/9)*sin(pi/18))
This is the code:
syms t1 t2 t3 L1 L2 L3
a=0; al=0; d=0; ct1=cos(t1); st1=sin(t1); sal=sin(al); cal=cos(al); T01=[ct1 -st1 0 a;st1*cal ct1*cal -sal -d*sal;st1*sal ct1*sal cal d*cal;0 0 0 1];
a=L1; al=0; d=0; ct2=cos(t2); st2=sin(t2); sal=sin(al); cal=cos(al); T12=[ct2 -st2 0 a;st2*cal ct2*cal -sal -d*sal;st2*sal ct2*sal cal d*cal;0 0 0 1];
a=L2; al=0; d=0; ct3=cos(t3); st3=sin(t3); sal=sin(al); cal=cos(al); T23=[ct3 -st3 0 a;st3*cal ct3*cal -sal -d*sal;st3*sal ct3*sal cal d*cal;0 0 0 1];
a=L3; T3H=[1 0 0 a;0 1 0 0;0 0 1 0;0 0 0 1];
T03=T01*T12*T23; T0H=T03*T3H;
disp('T03 for t1=0 t2=0 t3=0 :') subs(T03,[t1,t2,t3],[0,0,0])
disp('T0H for t1=0 t2=0 t3=0 :') subs(T0H,[t1,t2,t3],[0,0,0])
t11=pi*(10/180); t21=pi*(20/180); t31=pi*(30/180); disp('T03 for t1=10 t2=20 t3=30 :') T03n=subs(T03,[t1,t2,t3],[t11,t21,t31])
disp('T0H for t1=10 t2=20 t3=30 :') T0Hn=subs(T0H,[t1,t2,t3],[t11,t21,t31])
t12=pi*(1/2); t22=pi*(1/2); t32=pi*(1/2); disp('T03 for t1=90 t2=90 t3=90 :') T03n=subs(T03,[t1,t2,t3],[t12,t22,t32])
disp('T0H for t1=90 t2=90 t3=90 :') T0Hn=subs(T0H,[t1,t2,t3],[t12,t22,t32])

채택된 답변

A Jenkins
A Jenkins 2013년 10월 16일
편집: A Jenkins 2013년 10월 16일
vpa(T03n)
vpa(T0Hn)
help vpa
VPA Variable precision arithmetic.
R = VPA(S) numerically evaluates each element of the double matrix S using variable precision floating point arithmetic with D decimal digit accuracy, where D is the current setting of DIGITS.
  댓글 수: 1
Sina
Sina 2013년 10월 16일
Thanks, works perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by