ode45 to solve second order ODE
22 次查看(过去 30 天)
显示 更早的评论
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 个评论
Star Strider
2019-5-3
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!