# How to Solve Second Order ODE with 2 dependent variables

30 views (last 30 days)
Yanuar Rizki Pahlevi on 14 Jan 2021
Answered: Divija Aleti on 20 Jan 2021
Hi guys, I am trying to solve this second order ODE, I followed this step
diff(x,2)== diff(x)-y
Vx=odeToVectorField(diff(x,2)== diff(x)-y)
[Y; Y - y(t)] %result from odeToVectorField
diff(y,2)== diff(y)-x
Vy=odeToVectorField(diff(x,2)== diff(x)-y)
[[Y; Y - x(t)]] %result from odeToVectorField
i tried using odeToVectorField to make it in first order and got 2 vectors. but then I dont understand how to make this to work since on the vector from first DE, there is variable y(t) which always updated during calculation.. it also happened for vector from second DE..
I tried using this step
by creating
ode1=diff(x1)==x2;
ode2=diff(x2)==diff(x1)-y1
ode3=diff(y1)==y2
ode4=diff(y2)==diff(y1)-x1
odes1=[ode1;ode2]
odes2=[ode3;ode4]
but dsolve did not work for this.

Divija Aleti on 20 Jan 2021
Hi Yanuar,
Two second order ODE's can directly be solved by using 'dsolve'. Have a look at the following code:
syms x(t) y(t)
ode1 = diff(x,2)==diff(x)-y;
ode2 = diff(y,2)==diff(y)-x;
odes = [ode1;ode2];
S = dsolve(odes)
S.x
S.y
Another method would be to convert the two second order ODEs into four first order ODEs and then solve using dsolve.
Let x1 = x, y1 = y
dx1/dt = x2, dy1/dt = y2
dx2/dt = x2 - y1, dy2/dt = y2 - x1
syms x1(t) x2(t) y1(t) y2(t)
ode1=diff(x1)==x2;
ode2=diff(x2)==x2-y1;
ode3=diff(y1)==y2;
ode4=diff(y2)==y2-x1;
odes=[ode1;ode2;ode3;ode4];
S = dsolve(odes);
S.x1 % As x1 = x
S.y1 % As y1 = y
Output: R2020b

### Community Treasure Hunt

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

Start Hunting!