Solve for Nonlinear State Space Equation
4 views (last 30 days)
Show older comments
Trying to derive the Nonlinear steady state equation for a double pengelum. Solved for matrix [theta1;theta1dot;theta2;theta2dot]. Need in terms of [theta1dot;theta2doubledot;theta2dot;theta2doubledot]. Where theta1dot and theta2 dot would just be the variable but theta1doubledot and theta2doubledot would the values factored out of the respective equations.
solving for eqn 17 have matrix 18
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1221667/image.jpeg)
output for equation 17 in terms of 20
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1221672/image.jpeg)
clear; clc;
% Initalize variables
syms theta1(t) theta2(t) r1 r2 m1 m2 g u
% Initalize kinematic constraints
x1 = r1*sin(theta1);
y1 = -r1*cos(theta1);
x2 = x1+r2*sin(theta2+theta1);
y2 = y1-r2*cos(theta2+theta1);
% Initalize velocity equations
x1dot=diff(x1);
y1dot=diff(y1);
x2dot=diff(x2);
y2dot=diff(y2);
% Solve for potential energy
pe=m1*g*y1+m2*g*y2;
%Solve for kinetic energy
ke=1/2*m1*(x1dot^2+y1dot^2)+1/2*m2*(x2dot^2+y2dot^2);
simplify(ke);
% Solve for L=KE-PE
l=ke-pe;
simplify(l);
% Initalize variables
syms theta1dot theta2dot
% Solve for partial derivitive of L by theta1dot
eqn1=subs(diff(subs(l(t), diff(theta1(t)), theta1dot), theta1dot), theta1dot, diff(theta1(t)));
eqn1=simplify(eqn1);
% Solve for the time derivative of eqn1
eqn1=diff(eqn1);
eqn1=simplify(eqn1);
% Solve for partial derivitive of L by theta1
a=simplify(diff(l,theta1));
% Solve for first equation of motion
eqn1=simplify(eqn1-a)-u
% Solve for partial derivitive of L by theta2dot
eqn2=subs(diff(subs(l(t), diff(theta2(t)), theta2dot), theta2dot), theta2dot, diff(theta2(t)));
eqn2=simplify(eqn2);
% Solve for the time derivative of eqn2
eqn2=diff(eqn2);
eqn2=simplify(eqn2);
% Solve for partial derivitive of L by theta2
z=simplify(diff(l,theta2));
% Solve for second equation of motion
eqn2=simplify(eqn2-z)
[V,S] = odeToVectorField(subs(eqn1),subs(eqn2));
S=[S(3);S(4);S(1);S(2)]
V=[V(3);V(4);V(1);V(2)]
6 Comments
Torsten
on 7 Dec 2022
You are mistaken. "odeToVectorField" solved for d/dt theta1(t) , d^2/dt^2 theta1(t), d/dt theta2(t) , d^2/dt^2 theta2(t).
If it could solve theta1(t) and theta2(t), you wouldn't have to integrate the equations using an ODE integrator (the call to which is missing in your code) - you already had the solution.
Answers (0)
See Also
Categories
Find more on Particle & Nuclear Physics 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!