Need help solving second order differential equations using ODE45

6 ビュー (過去 30 日間)
Mark Purdy
Mark Purdy 2012 年 2 月 23 日
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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by