How to solve ODE system numerically

74 visualizaciones (últimos 30 días)
Ángel AM
Ángel AM el 6 de Mayo de 2021
Comentada: Ángel AM el 6 de Mayo de 2021
Hello. I am trying to get a solution from this system:
a1 = 0.7;
a2 = 0.4;
b1 = 0.06;
b2 = 0.08;
c1 = 8787168;
c2 = 8111232;
syms x(t) y(t);
ode1 = diff(x) == (-a1)*x + b1*(c1-x)*y;
ode2 = diff(y) == (-a2)*y + b2*(c2-y)*x;
odes = [ode1,ode2]
cond1 = x(0) == 15000;
cond2 = y(0) == 17000;
conds = [cond1,cond2]
dsolve(odes,conds);
But Matlab cannot come to an explicit solution. How can I produce a numerical one?
Thank you.

Respuesta aceptada

Jan
Jan el 6 de Mayo de 2021
Editada: Jan el 6 de Mayo de 2021
a1 = 0.7;
a2 = 0.4;
b1 = 0.06;
b2 = 0.08;
c1 = 8787168;
c2 = 8111232;
y0 = [15000, 17000];
tSpan = [0, 0.0001]; % The values explode for higher t
[Y, T] = ode45(@(t,y) fcn(t, y, a1, a2, b1, b2, c1, c2), tSpan, y0);
plot(T, Y)
function dy = fcn(t, y, a1, a2, b1, b2, c1, c2)
dy = [-a1 * y(1) + b1 * (c1 - y(1)) * y(2); ...
-a2 * y(2) + b2 * (c2 - y(2)) * y(1)];
end

Más respuestas (1)

Alan Stevens
Alan Stevens el 6 de Mayo de 2021

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by