Need help solving second order differential equations using ODE45

2 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Jiro Doke
Jiro Doke el 23 de Feb. de 2012
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 comentario
Mark Purdy
Mark Purdy el 10 de Mzo. de 2012
Hey, this was very useful, and put me on the right track, much appreciated!

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by