# Matlab help - 2nd order ODE

1. Mar 12, 2015

### intrinsik

I'm trying to solve a 2nd order differential equation in matrix form. I'm not familiar with Matlab, and have tried solving this using tutorials on youtube.
Initially, theta1 = pi/4, theta2 = 7*pi/12, theta1_d = 0, and theta2_d =0. Time interval is (0,1.2).
When I try to solve this using ode45, I keep getting an error in my equation for dy (last line of function), and I'm not sure what i'm doing wrong. Can anyone help me out?

The equation I'm trying to solve is of the form
A*[theta1_dd;theta2_dd] + B*[theta1_d;theta2_d] = C
where theta1_d is the first derivative of theta, theta1_dd is the second derivative of theta, etc.

function dy = ode(t,y)
m1=2.52;
m2=1.30;
l1=0.33;
l2=0.32;
r1=l1/2;
r2=l2/2;
ic1=(m1*l1^2)/12;
ic2=(m2*l2^2)/12;
i1=ic1+(m1*r1^2);
i2=ic2+(m2*r2^2);
syms theta1 theta2 theta1_d theta2_d theta1_dd theta2_dd t1 t2;
A=[i1+(m2*l1^2), m2*r2*l1*cos(theta2-theta1);m2*r2*l1*cos(theta2-theta1), i2]
B=[0,-m2*r2*l1*sin(theta2-theta1)*theta2_d;-m2*r2*l1*sin(theta2-theta1)*theta1_d,0]
C=[t1-t2;t2]
u1=y(1);
u2=y(2);
dy=[u2;(C/A)-((B/A)*u2)];
end

Last edited: Mar 12, 2015
2. Mar 12, 2015

### Staff: Mentor

If you have two coupled 2nd order equations, you need to convert to a system of 4 coupled 1st order equations.

3. Mar 12, 2015