Need help solving second order differential equations using ODE45
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposta accettata
Jiro Doke
il 23 Feb 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].
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!