Sym 1x1 in Matrix

조회 수: 25 (최근 30일)
Jaehyun Park
Jaehyun Park 2022년 2월 20일
답변: Paul 2022년 2월 20일
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?
  댓글 수: 1
Jaehyun Park
Jaehyun Park 2022년 2월 20일
Suprisingly, It's now converted that P2 is sym 1x1 and P3 is sym 3x1.....

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

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2022년 2월 20일
That .... dot dot represents the continuation in same line
Continue Long Statements on Multiple Lines

Paul
Paul 2022년 2월 20일
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
P2(t) = 
P3
P3 = 
whos P2 P3
Name Size Bytes Class Attributes P2 1x1 8 symfun P3 3x1 8 sym
P2 is a symfun but P3 is a sym. P2 does return a 3x1 for a specified value of t:
P2(1)
ans = 
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
Name Size Bytes Class Attributes P2 3x1 8 sym
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.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by