ODE System with 4 equations

122 visualizaciones (últimos 30 días)
Baris Gungordu
Baris Gungordu el 5 de Mayo de 2020
Comentada: Torsten el 25 de Sept. de 2022
Hi all,
I have a system with 4 ODEs which I want to solve simultanously.Each equations are feeded with some variables. All derivatives are with respect to time (t) only. The variables are x,v,p and u.
dx/dt = v(t)
dv/dt = - 2*v(t) - 1000*x(t) - p(t)
dp/dt = v(t) - u(t)
du/dt = p(t) - abs(u(t) * u(t)
Initial conditions are all zero at t = 0, i.e. x(0) = 0; v(0) = 0; p(0) = 0; u(0) = 0.
Looking forward to get your help.
I don't have any preference over the integration scheme but an application of ode45 should help. I also have access to the symbolic toolbox.
Best regards,
Baris
  1 comentario
Malak Abuhusien
Malak Abuhusien el 14 de Jun. de 2021
Editada: Malak Abuhusien el 14 de Jun. de 2021
how solution with for loop?

Iniciar sesión para comentar.

Respuesta aceptada

Josh Meyer
Josh Meyer el 5 de Mayo de 2020
Editada: Josh Meyer el 5 de Mayo de 2020
When you have a system of equations, each equation gets its own spot in the solution vector y.
With the conventions
y(1) = x, dydt(1) = dx/dt
y(2) = v, dydt(2) = dv/dt
y(3) = p, dydt(3) = dp/dt
y(4) = u, dydt(4) = du/dt
You can write the system of equations in an ODE function as
function dydt = ODEsystem(t,y)
dydt = zeros(4,1);
dydt(1) = y(2);
dydt(2) = - 2*y(2) - 1000*y(1) - y(3);
dydt(3) = y(2) - y(4);
dydt(4) = y(3) - abs(y(4) * y(4));
end
After you save the function in a file in your current directory, you can set the initial conditions and integrate with:
y0 = zeros(4,1);
tspan = [0 10];
[t,y] = ode45(@ODEsystem,tspan,y0);
plot(t,y,'-o')
For your problem, with the initial conditions all zero, this integration doesn't do much because all of the terms in the equations depend on x, v, y, or p, so the terms all remain zero.
  7 comentarios
RITIKA Jaiswal
RITIKA Jaiswal el 25 de Sept. de 2022
what do do if we have odes of dimension 100.Since it was of order 4 we can easily write that but what if have order of 100 how can we implement that in our code?
please help.
Torsten
Torsten el 25 de Sept. de 2022
If there are regularities in the dydt terms, you can usually use a loop to set them up.
If not, you will have to write them down one by one.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by