Clear Filters
Clear Filters

Solve for Nonlinear State Space Equation

9 views (last 30 days)
Cason Cox
Cason Cox on 6 Dec 2022
Commented: Torsten on 7 Dec 2022
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
output for equation 17 in terms of 20
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
eqn1(t) = 
% 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)
eqn2(t) = 
[V,S] = odeToVectorField(subs(eqn1),subs(eqn2));
S=[S(3);S(4);S(1);S(2)]
S = 
V=[V(3);V(4);V(1);V(2)]
V = 
  6 Comments
Cason Cox
Cason Cox on 6 Dec 2022
Sorry, yes that is what I meant.
"odeToVectorField" solved for [theta1(t); d/dt theta1(t); theat2(t); d/dt theta2(t)] but I am trying to solve for the matrix with [d/dt theta1(t); d^2/dt^2 theta1(t); d/dt theta2(t); d^2/dt^2 theta2(t)]
Torsten
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.

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!