Need help solving second order differential equations using ODE45

조회 수: 1 (최근 30일)
Hey all,
This is my first post on the community so not entirely sure how it works but here goes!
I'm trying to solve a second order differential equation in the form:
x'' = - (γ*x')+ (x*w^2)-(e*x^3) + F(t); where x is being differentiated with respect to t.
I've been asked to solve it using the ode45 function and I've spent a while looking at the help in MatLab but I'm stuck. I think I understand how the ode45 function works but I'm not sure how to put the differential equation into a form that Matlab will understand.
So far I have:
function dx = fx(t,x);
%have global variables w, y, e, F
dx = zeros (2,1);
dx(1) = x(2);
dx(2)= -y*x(2) + x(1)*w^2 + e*(x(1))^3 + F;
end
and then I try:
[T,X] = ode45(@fx, [0 4000], [0 0 1]);
I'm trying to integrate it over t=0 to 4000, and with the intial conditions x=0; dx/dt= 1; at t=0. I've looked at other examples but they've generally been just first order differentials with only two initial conditions. Do I have to add a 3rd part to my 'fx' function to take into account the dx/dt part of the equation, and how would I do this? I'm very much a MATLAB novice and any advice would be appreciated!

채택된 답변

Jiro Doke
Jiro Doke 2012년 2월 23일
The initial conditions imply that t=0, so you simply need to pass in the two initial conditions for x and dx/dt. So for your example, [0 1], not [0 0 1].
  댓글 수: 1
Mark Purdy
Mark Purdy 2012년 3월 10일
Hey, this was very useful, and put me on the right track, much appreciated!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by