Solving equations for a specified variable in terms of other variables
Show older comments
I am trying to solve euqation (13) and (16) as listed on this website https://www.myphysicslab.com/pendulum/double-pendulum-en.html
This is what I have attempted so far however I am running into errors
syms g x1 y1 x2 y2 l1 l2 m1 m2 theta1 theta2 omega1 omega2 alpha1 alpha2 dy1 dy2 dx1 dx2 d2y1d d2y2 d2x1 d2x2
x1= l1*sin(theta1);
y1= -l1*cos(theta1);
x2 = x1+l2*sin(theta2);
y2 = y1-l2*cos(theta2);
dx1 = omega1*l1*cos(theta1);
dy1 = omega1*l1*sin(theta1);
dx2 = dx1 + omega2*l2*cos(theta2);
dy2 = dy1 + omega2*l2*sin(theta2);
d2x1 = -omega1^2*l1*sin(theta1)+alpha1*l1*cos(theta1);
d2y1 = omega1^2*l1*cos(theta1)+alpha1*l1*sin(theta1);
d2x2 = d2x1-omega2^2*l2*sin(theta2)+alpha2*l2*cos(theta2);
d2y2 = d2y1+omega2^2*l2*cos(theta2)+alpha2*l2*sin(theta2);
solve('sin(theta1)*(m1*d2y1+m2*d2y2+m2*g+m1*g)==-cos(theta1)*(m1*d2x1+m2*d2x2)', 'alpha1')
solve('sin(theta2)*(m2*d2y2+m2*g)==-cos(theta2)*m2*d2x2', 'alpha2')
Any help is much appreciated
Answers (1)
Eugenio Grabovic
on 30 Jan 2019
Edited: Eugenio Grabovic
on 30 Jan 2019
syms g l1 l2 m1 m2 theta1 theta2 omega1 omega2 alpha1 alpha2
x1= l1*sin(theta1);
y1= -l1*cos(theta1);
x2 = x1+l2*sin(theta2);
y2 = y1-l2*cos(theta2);
dx1 = omega1*l1*cos(theta1);
dy1 = omega1*l1*sin(theta1);
dx2 = dx1 + omega2*l2*cos(theta2);
dy2 = dy1 + omega2*l2*sin(theta2);
d2x1 = -omega1^2*l1*sin(theta1)+alpha1*l1*cos(theta1);
d2y1 = omega1^2*l1*cos(theta1)+alpha1*l1*sin(theta1);
d2x2 = d2x1-omega2^2*l2*sin(theta2)+alpha2*l2*cos(theta2);
d2y2 = d2y1+omega2^2*l2*cos(theta2)+alpha2*l2*sin(theta2);
eq1 = sin(theta1)*(m1*d2y1+m2*d2y2+m2*g+m1*g)==-cos(theta1)*(m1*d2x1+m2*d2x2);
eq2 = sin(theta2)*(m2*d2y2+m2*g)==-cos(theta2)*m2*d2x2;
solutions = solve([eq1 eq2],[alpha1 alpha2])
If u check solver helper its written that it doesn't accept char vectors anymore and requires just symbolycs. Should be working now. In addition a system of equations requires to be solved within the same solver.
9 Comments
Alastair Poore
on 30 Jan 2019
madhan ravi
on 30 Jan 2019
which release are you using?
Alastair Poore
on 30 Jan 2019
Eugenio Grabovic
on 30 Jan 2019
"When using your edit it returns ans=alpha1 and ans=alpha2, whereas I'm looking for it to return alpha1 and alpha2 in terms of all the other variables (as given on the website I linked)."
My apologies, i din't actually verify the results. I edited my main answer with the solution.
Alastair Poore
on 30 Jan 2019
Alastair Poore
on 30 Jan 2019
Eugenio Grabovic
on 30 Jan 2019
Edited: Eugenio Grabovic
on 30 Jan 2019
solutions =
struct with fields:
alpha1: [1×1 sym]
alpha2: [1×1 sym]
>> solutions.alpha1
ans =
-(g*m1*cos(theta2)^2*sin(theta1) + g*m2*cos(theta2)^2*sin(theta1) + g*m1*sin(theta1)*sin(theta2)^2 - l2*m2*omega2^2*cos(theta1)*sin(theta2)^3 + l2*m2*omega2^2*cos(theta2)^3*sin(theta1) - g*m2*cos(theta1)*cos(theta2)*sin(theta2) - l1*m2*omega1^2*cos(theta1)*sin(theta1)*sin(theta2)^2 + l1*m2*omega1^2*cos(theta2)*sin(theta1)^2*sin(theta2) + l2*m2*omega2^2*cos(theta2)*sin(theta1)*sin(theta2)^2 + l1*m2*omega1^2*cos(theta1)*cos(theta2)^2*sin(theta1) - l1*m2*omega1^2*cos(theta1)^2*cos(theta2)*sin(theta2) - l2*m2*omega2^2*cos(theta1)*cos(theta2)^2*sin(theta2))/(l1*(m1*cos(theta1)^2*cos(theta2)^2 + m1*cos(theta1)^2*sin(theta2)^2 + m1*cos(theta2)^2*sin(theta1)^2 + m2*cos(theta1)^2*sin(theta2)^2 + m2*cos(theta2)^2*sin(theta1)^2 + m1*sin(theta1)^2*sin(theta2)^2 - 2*m2*cos(theta1)*cos(theta2)*sin(theta1)*sin(theta2)))
>> solutions.alpha2
ans =
-(g*m1*cos(theta1)^2*sin(theta2) + g*m2*cos(theta1)^2*sin(theta2) - l1*m1*omega1^2*cos(theta2)*sin(theta1)^3 + l1*m1*omega1^2*cos(theta1)^3*sin(theta2) - l1*m2*omega1^2*cos(theta2)*sin(theta1)^3 + l1*m2*omega1^2*cos(theta1)^3*sin(theta2) - g*m1*cos(theta1)*cos(theta2)*sin(theta1) - g*m2*cos(theta1)*cos(theta2)*sin(theta1) + l1*m1*omega1^2*cos(theta1)*sin(theta1)^2*sin(theta2) + l1*m2*omega1^2*cos(theta1)*sin(theta1)^2*sin(theta2) + l2*m2*omega2^2*cos(theta1)*sin(theta1)*sin(theta2)^2 - l2*m2*omega2^2*cos(theta2)*sin(theta1)^2*sin(theta2) - l1*m1*omega1^2*cos(theta1)^2*cos(theta2)*sin(theta1) - l1*m2*omega1^2*cos(theta1)^2*cos(theta2)*sin(theta1) - l2*m2*omega2^2*cos(theta1)*cos(theta2)^2*sin(theta1) + l2*m2*omega2^2*cos(theta1)^2*cos(theta2)*sin(theta2))/(l2*m1*cos(theta1)^2*cos(theta2)^2 + l2*m1*cos(theta1)^2*sin(theta2)^2 + l2*m1*cos(theta2)^2*sin(theta1)^2 + l2*m2*cos(theta1)^2*sin(theta2)^2 + l2*m2*cos(theta2)^2*sin(theta1)^2 + l2*m1*sin(theta1)^2*sin(theta2)^2 - 2*l2*m2*cos(theta1)*cos(theta2)*sin(theta1)*sin(theta2))
This is what i am getting after running it. The only difference is that I am using R2018b... im sorry i actually don't know where is the problem then.
madhan ravi
on 30 Jan 2019
+1 Eugenio , appreciate your effort,
you can also change your last line to:
[alpha1 alpha2] = solve([eq1 eq2],[alpha1 alpha2])
Alastair Poore
on 30 Jan 2019
Categories
Find more on Equation Solving 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!