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.(adsbygoogle = window.adsbygoogle || []).push({});

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

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab help - 2nd order ODE

Loading...

Similar Threads - Matlab help order | Date |
---|---|

Matlab MATLab: Not enough inputs for nlinfit | Nov 16, 2017 |

Matlab Help needed to fix a matlab code | Nov 8, 2017 |

New to Matlab, help with vectors | Feb 20, 2016 |

Help with Matlab solving second order differential equations | Oct 19, 2010 |

2nd Order ODE in MATLAB help | Jan 14, 2008 |

**Physics Forums - The Fusion of Science and Community**