ode45 to solve second order ODE
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hey guys,
I'm trying to use Matlab to solve a second-order ODE that's basically an equation of motion derived from the Lagrangian equation. I'm supposed to solve it using various initial conditions, then theta(0)=10 degrees, theta(0)=20 degrees, theta(0)=30 degrees, theta(0)=40 degrees, all whereby thetadot(0) (basically diff(theta,t)) = 0.
Below is my code:
syms m g p theta(t) r thetadot I Theta
%I = m*r^2*(3/2*8/(3*pi));
omega=diff(theta,t)
h = p*(1-cos(theta));
T=0.5*I*(omega^2);
V=m*g*h;
%d2y = diff(theta,t,2)
L = T-V
L1 = subs(L,omega,thetadot);
L1diff = diff(L1,thetadot);
L2 = subs(L,theta,Theta)
L2new=diff(L2,Theta)
L3 = subs(L1diff,thetadot,omega)
L3diff = diff(L3,t)
EOM = L3-L2 == 0
cond2 = 0; %dy(0)
cond1 = 0.174; %theta(0)
I have been able to get my equation of motion and I was given such conditions, but I have no idea how to solve a second-order ODE with ode45, and the documentation is rather abstract. Any help would be greatly appreciated. Thanks all!
2 comentarios
Star Strider
el 3 de Mayo de 2019
I can’t figure out what your differential equation is, even after running your code.
Use the odeToVectorField function to create a vector field from your second-order ODE, then matlabFunction to convert the first output of odeToVectorField to an anonymous function that you can use with ode45.
Respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!