Sym 1x1 in Matrix
9 views (last 30 days)
Show older comments
syms th1(t) th2(t) th3(t) th1_d(t) th2_d(t) th3_d(t) a1 a2 a3 m1 m2 m3 g
P2 = [a2*cos(th1)*cos(th2)/2; a2*sin(th1)*cos(th2)/2; a2*sin(th2)/2+a1];
P3 = [a2*cos(th1(t))*cos(th2(t)) + (a3*cos(th1(t))*cos(th2(t))*cos(th3(t)))/2 - (a3*cos(th1(t))*sin(th2(t))*sin(th3(t)))/2;...
a2*cos(th2(t))*sin(th1(t)) + (a3*cos(th2(t))*cos(th3(t))*sin(th1(t)))/2 - (a3*sin(th1(t))*sin(th2(t))*sin(th3(t)))/2;...
a1 + a2*sin(th2(t)) + (a3*cos(th2(t))*sin(th3(t)))/2 + (a3*cos(th3(t))*sin(th2(t)))/2];
Hi. I'm trying to get P3 in sym matrix, however, it appears 1x1 always.
However, P2 appears 3x1 sym matrix.
I have no idea what's the diffrence between them and how can I convert it to 3x1 matrix?
Answers (2)
KALYAN ACHARJYA
on 20 Feb 2022
That .... dot dot represents the continuation in same line
Continue Long Statements on Multiple Lines
0 Comments
Paul
on 20 Feb 2022
syms th1(t) th2(t) th3(t) th1_d(t) th2_d(t) th3_d(t) a1 a2 a3 m1 m2 m3 g
P2 = [a2*cos(th1)*cos(th2)/2; a2*sin(th1)*cos(th2)/2; a2*sin(th2)/2+a1];
P3 = [a2*cos(th1(t))*cos(th2(t)) + (a3*cos(th1(t))*cos(th2(t))*cos(th3(t)))/2 - (a3*cos(th1(t))*sin(th2(t))*sin(th3(t)))/2;...
a2*cos(th2(t))*sin(th1(t)) + (a3*cos(th2(t))*cos(th3(t))*sin(th1(t)))/2 - (a3*sin(th1(t))*sin(th2(t))*sin(th3(t)))/2;...
a1 + a2*sin(th2(t)) + (a3*cos(th2(t))*sin(th3(t)))/2 + (a3*cos(th3(t))*sin(th2(t)))/2];
P2
P3
whos P2 P3
P2 is a symfun but P3 is a sym. P2 does return a 3x1 for a specified value of t:
P2(1)
I'm not sure why P3 is not also a symfun. The only difference I see is that the creation of P3 uses th1(t), etc. as explicit functions of t and P2 does not. I didn't think that should matter, but maybe it does. Let's try:
syms th1(t) th2(t) th3(t) th1_d(t) th2_d(t) th3_d(t) a1 a2 a3 m1 m2 m3 g
P2 = [a2*cos(th1(t))*cos(th2(t))/2; a2*sin(th1(t))*cos(th2(t))/2; a2*sin(th2(t))/2+a1];
whos P2
So it does matter. If you want P2 and P3 to both be 1x1 symfun objects that are vector valued functions of a scalar variable, then don't use the explicit th1(t), etc. in their defintions. Or if you want both to be 3x1 sym objects, then do use the explicit th1(t) in their definitions. If P2 and P3 should be symfun, it would be clearer to use
P2(t) = ....
P3(t) = ....
in which case it won't matter if the elements on the rhs are shown as explciit functions of t.
0 Comments
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!