Hi guys,
I had my first code run which gives me the equations of motion.
eqx1 = M1*y1dd - F + K*(s0 + y1 - y2 - r*sin(ph))
eqx2 = F + M2*y2dd - K*(s0 + y1 - y2 - r*sin(ph))
eqx3 = I*phdd + F*r*cos(ph) - K*r*cos(ph)*(s0 + y1 - y2 - r*sin(ph))
where all the variables were defined as symm
syms M1 M2 I K;
syms t y1 y1d y1dd y2 y2d y2dd ph phd phdd;
Now, I tried replacing the y1d, y1dd, y2d, y2dd etc with diff(y1,t), diff(y1,t,2) respectively.
fx1=subs(eqx1,{y1,y1d,y1dd,y2,y2d,y2dd,ph,phd,phdd},{y1(t),diff(y1,t),diff(y1,t,2),y2(t),diff(y2,t),diff(y2,t,2),ph(t),diff(ph,t),diff(ph,t,2)})==0
Output:
fx1=M1*D(D(y1))(t) - F + K*(s0 + y1 - y2 - r*sin(ph)) == 0
now when I run
diff(fx1), i get
>> diff(fx1)
ans =
K == 0
>> diff(fx1,t)
ans =
M1*diff(D(D(y1))(t), t) == 0
Now, I tried directly defining f (same as fx1)
>> f = M1*diff(y1,t,2) - F + K*(s0 + y1(t) - y2(t) - r*sin(ph(t))) == 0
f(t) =
M1*D(D(y1))(t) - F + K*(s0 + y1(t) - y2(t) - r*sin(ph(t))) == 0
>> diff(f)
ans(t) =
M1*D(D(D(y1)))(t) - K*(D(y2)(t) - D(y1)(t) + r*D(ph)(t)*cos(ph(t))) == 0
how do I get the above for fx1.
How do I come from fx1 to f

 Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Oct. de 2016

0 votos

syms fx1(t)
fx1(t) = subs(....)

5 comentarios

yashwant kolluru
yashwant kolluru el 16 de Oct. de 2016
Editada: Walter Roberson el 16 de Oct. de 2016
i already tried that, unfortunately it didn't work!
The below is the output I got
fx1(t)=subs(eqx1,{y1,y1d,y1dd,y2,y2d,y2dd,ph,phd,phdd},{y1(t),diff(y1,t),diff(y1,t,2),y2(t),diff(y2,t),diff(y2,t,2),ph(t),diff(ph,t),diff(ph,t,2)})==0
fx1(t) =
M1*D(D(y1))(t) - F + K*(s0 + y1 - y2 - r*sin(ph)) == 0
>> diff(fx1)
ans(t) =
M1*D(D(D(y1)))(t) == 0
>> diff(fx1,t)
ans(t) =
M1*D(D(D(y1)))(t) == 0
Your posted code is not functional in R2016b
syms M1 M2 I K;
syms t y1 y1d y1dd y2 y2d y2dd ph phd phdd;
%you did not declare these
syms F s0 r
%you cannot have y1(t) and ph(t) on the values to substitute in unless they have been declared as functions
syms y1(t) y2(t) ph(t)
eqx1 = M1*y1dd - F + K*(s0 + y1 - y2 - r*sin(ph));
eqx2 = F + M2*y2dd - K*(s0 + y1 - y2 - r*sin(ph));
eqx3 = I*phdd + F*r*cos(ph) - K*r*cos(ph)*(s0 + y1 - y2 - r*sin(ph));
%for convenience, they make the code easier to debug
source = {y1(t), diff(y1,t), diff(y1,t,2), y2(t), diff(y2,t), diff(y2,t,2), ph(t), diff(ph,t), diff(ph,t,2)};
dest = {y1, y1d, y1dd, y2, y2d, y2dd, ph, phd, phdd};
fx1 = subs(eqx1,dest,source)==0;
Be sure to clear your workspace before executing these; existing definitions of syms y1 y2 ph can mess up what happens later.
yashwant kolluru
yashwant kolluru el 17 de Oct. de 2016
Editada: Walter Roberson el 17 de Oct. de 2016
I did replacing y1 to y1(t) and others also.But that also doesn't work.
The below is the output.
eqx1 =
M1*y1dd - F + K*(s0 + y1 - y2 - r*sin(ph))
eqx2 =
F + M2*y2dd - K*(s0 + y1 - y2 - r*sin(ph))
eqx3 =
I*phdd + F*r*cos(ph) - K*r*cos(ph)*(s0 + y1 - y2 - r*sin(ph))
>> syms y1(t) y2(t) ph(t)
>> source = {y1(t), diff(y1,t), diff(y1,t,2), y2(t), diff(y2,t), diff(y2,t,2), ph(t), diff(ph,t), diff(ph,t,2)};
dest = {y1, y1d, y1dd, y2, y2d, y2dd, ph, phd, phdd};
>> fx1 = subs(eqx1,dest,source)==0
fx1 =
M1*D(D(y1))(t) - F + K*(s0 + y1 - y2 - r*sin(ph)) == 0
>> diff(fx1)
ans =
K == 0
>>
Note : I am using matlab 2012b
Walter Roberson
Walter Roberson el 17 de Oct. de 2016
We need your exact code, all the syms declarations, the actual assignments to eqx1, everything.
I just installed R2012b, and copied and pasted the code I posted above, and it worked fine.
>> fx1 = subs(eqx1,dest,source)==0
fx1(t) =
M1*D(D(y1))(t) - F + K*(s0 + y1(t) - y2(t) - r*sin(ph(t))) == 0

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Oct. de 2016

Comentada:

el 17 de Oct. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by