third order nonlinear differential equation numerical solution
Afficher commentaires plus anciens
Hi all, I am trying to solve the following equation,
y * y''' = -1
y(0) = 1, y'(0) = 0, y''(0) = 0
to do so, I am using the following simple code with ode45
function test()
[T, Y] = ode45(@linearized, [0 3], [1 0 0 0]);
figure; plot(T, Y(:,1))
axis([0 3 0 1.2])
% linearization
function dy = linearized(t,y)
dy = zeros(4,1);
dy(1) = y(2);
dy(2) = y(3);
dy(3) = y(4);
dy(4) = -1*y(3)*y(1)-1;
end
end
However, it gives me the wrong answer. Do you have any suggestion here?
Réponses (1)
John D'Errico
le 30 Déc 2014
Modifié(e) : John D'Errico
le 30 Déc 2014
So lets look at how you would convert this to a system of ODEs. We have:
y*y''' = -1
So as a system, we have three variables to solve for, y, y', and y''. As you can see, you were given starting values for all three "variables", but there is no starting value for y'''. You don't need one.
I'll write out what the system is, as a system of differential equations.
y' = y(2)
y'' = y(3)
y''' = -1/y(1)
So now we can write the function in a simple function handle form...
dy = @(t,y) [y(2);y(3);-1./y(1)];
If you prefer, an explicit nested function would have worked too, as you did, or an external m-file function.
[T, Y] = ode45(dy, [0 3], [1 0 0]);
plot(T,Y,'-')
grid on

The blue curve is y(t). It looks like something of interest happens near 1.7779 or so. If we look at the curve in blue, that is where y(t) wants to cross through zero. That would clearly be a derivative singularity, since y'''=-1/y.
2 commentaires
Mazi
le 30 Déc 2014
John D'Errico
le 30 Déc 2014
Modifié(e) : John D'Errico
le 30 Déc 2014
Because you returned a function handle there, not a vector of differential elements!
As you wrote it, do this instead:
dy = [y(2);y(3);-1./y(1)];
See that I created a function handle for my function, and then passed that directly into ode45. Whereas you have used a nested function. It needs to return a vector, which is what my solution did.
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!