How to solve ODE system numerically

5 views (last 30 days)
Ángel AM on 6 May 2021
Commented: Ángel AM on 6 May 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.

Jan on 6 May 2021
Edited: Jan on 6 May 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
Ángel AM on 6 May 2021
Thank you very much.

Alan Stevens on 6 May 2021
help ode45