ode45 to solve second order ODE
조회 수: 14 (최근 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!