How to solve ODE system numerically
79 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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
More Answers (1)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!