Symbolic matrix with sine and cosine to numerical values.

조회 수: 16(최근 30일)
Boris Cnossen
Boris Cnossen 2020년 9월 20일
답변: VBBV 2021년 11월 23일
I have this code:
syms sin(q1) sin(q2) sin(q4) sin(q3) sin(q5) cos(q1) cos(q2) cos(q3) cos(q4) cos(q5) L1 L2 L3 L4 L5 L6
T01=[cos(q1) -sin(q1) 0 0;
sin(q1) cos(q1) 0 0;
0 0 1 L1;
0 0 0 1];
T12=[cos(q2) -sin(q2) 0 0;
sin(q2) cos(q2) 0 0;
0 -1 0 0;
0 0 0 1];
T23=[cos(q3) -sin(q3) 0 L2;
sin(q3) cos(q3) 0 0;
0 0 1 0;
0 0 0 1];
T34= [cos(q4) -sin(q4) 0 L4;
0 0 1 -L3-L5;
sin(q4) cos(q4) 0 0;
0 0 0 1];
T45= [cos(q5) -sin(q5) 0 0;
0 0 1 0;
sin(q5) cos(q5) 0 0;
0 0 0 1];
T56 = [0 1 0 0;
0 0 -1 -L6;
-1 0 0 0;
0 0 0 1];
T06=T01*T12*T23*T34*T45*T56;
L1 = 17; % note: all lengths are given in cm.
L2 = 17;
L3 = 7;
L4 = 4;
L5 = 4;
L6 = 9;
q1=0;
q2=pi/2;
q3=pi/2;
q4=-pi/2;
q5=0;
q6=0;
subs(T06)
//
I want to calculate the numerical values of the matrix T06. However, i am not able to that since the sine and cosine are symbolic functions now. When i use subs(T06) i then get a matrix with stuff like sin(0) and cos(0), but it doesnt calculate it but rather gives it as just sin(0) and cos(0). What can i do?

답변(2개)

madhan ravi
madhan ravi 2020년 9월 20일
편집: madhan ravi 2020년 9월 20일
double(subs(T06))
%or
vpa(subs(T06))
  댓글 수: 2

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


VBBV
VBBV 2021년 11월 23일
syms q1 q2 q3 q4 q5 q6 L1 L2 L3 L4 L5 L6
% sin(q1) sin(q2) sin(q4) sin(q3) sin(q5) cos(q1) cos(q2) cos(q3) cos(q4) cos(q5)
T01=[cos(q1) -sin(q1) 0 0;
sin(q1) cos(q1) 0 0;
0 0 1 L1;
0 0 0 1];
T12=[cos(q2) -sin(q2) 0 0;
sin(q2) cos(q2) 0 0;
0 -1 0 0;
0 0 0 1];
T23=[cos(q3) -sin(q3) 0 L2;
sin(q3) cos(q3) 0 0;
0 0 1 0;
0 0 0 1];
T34= [cos(q4) -sin(q4) 0 L4;
0 0 1 -L3-L5;
sin(q4) cos(q4) 0 0;
0 0 0 1];
T45= [cos(q5) -sin(q5) 0 0;
0 0 1 0;
sin(q5) cos(q5) 0 0;
0 0 0 1];
T56 = [0 1 0 0;
0 0 -1 -L6;
-1 0 0 0;
0 0 0 1];
L1 = 17; % note: all lengths are given in cm.
L2 = 17;
L3 = 7;
L4 = 4;
L5 = 4;
L6 = 9;
% q1=0;
% q2=pi/2
% q3=pi/2
% q4=-pi/2
% q5=0;
% q6=0;
T06=subs(T01,{q1,L1},{0 17}).*subs(T12,{q2,L2},{pi/2, 17}).*subs(T23,{q3, L3},{pi/2 7}).*subs(T34,{q4, L4},{-pi/2 4}).*subs(T45,{q5, L5},{0 4}).*subs(T56,{(q6),L6},{0 9})
T06 = 
You can define the symbolic variables first used in product matrices and then use subs instead

Community Treasure Hunt

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

Start Hunting!

Translated by