Coding a system of differential equations

This is the system
dx/dt=y^2/x ,
dy/dt=x^2/y
with initial conditions x(0)=√ 2 , y(0)=0
i know how to do them separately but how do you put them in a system

 Réponse acceptée

Torsten
Torsten le 5 Jan 2022
Modifié(e) : Torsten le 5 Jan 2022
Numerically solving the original system will make difficulties because of the singularity at t=0 for y.
So let's first rewrite the equations:
y^2 = x*dx/dt
-> 2*y*dy/dt = x*d^2x/dt^2 + (dx/dt)^2
-> 0.5*(x*d^2x/dt^2 + (dx/dt)^2) = x^2
-> x*d^2x/dt^2 + (dx/dt)^2 - 2*x^2 = 0
Thus solve
x*d^2x/dt^2 + (dx/dt)^2 - 2*x^2 = 0
x(0) = sqrt(2), dx/dt(0) = 0
and it follows that
y = sqrt(x*dx/dt) or y=-sqrt(x*dx/dt)
Since you said you know how to solve one equation, I think you need no further help.

6 commentaires

James Sm.
James Sm. le 5 Jan 2022
So i just solve the last one and i'm done?
Yes, you solve
x*d^2x/dt^2 + (dx/dt)^2 - 2*x^2 = 0
x(0) = sqrt(2), dx/dt(0) = 0
and you are done.
Because of the singularity at t=0 for y, you get two possible solutions for y that can directly be deduced from the solution for x from above:
y = sqrt(x*dx/dt) or y=-sqrt(x*dx/dt)
James Sm.
James Sm. le 9 Jan 2022
I'm sorry i'm fairly new to matlab and i haven't solved this kind of equation
can you help
function main
x0 = [sqrt(2);0];
tspan = [0 2];
fun = @(t,x)[x(2);(-x(2)^2+2*x(1)^2)/x(1)];
[T,X] = ode15s(fun,tspan,x0);
Y = sqrt(X(:,1).*X(:,2)); % or Y = -sqrt(X(:,1).*X(:,2));
SOL = horzcat(X(:,1),Y);
plot(T,SOL)
end
James Sm.
James Sm. le 9 Jan 2022
ok ok i somewhat get it now
thank you
Remark:
The second-order ODE for x has to be rewritten as a system of two first-order ODEs where
x(1) = x and x(2) = dx/dt.
The system reads
dx(1)/dt = x(2)
dx(2)/dt = (-x(2)^2+2*x(1)^2)/x(1)
This is implemented in
fun = @(t,x)[x(2);(-x(2)^2+2*x(1)^2)/x(1)];

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by