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

 Accepted Answer

Torsten
Torsten on 5 Jan 2022
Edited: Torsten on 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 Comments

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)
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
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)];

Sign in to comment.

More Answers (0)

Products

Release

R2015a

Asked:

on 5 Jan 2022

Commented:

on 9 Jan 2022

Community Treasure Hunt

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

Start Hunting!