How to solve ODE system numerically

조회 수: 22 (최근 30일)
Ángel AM
Ángel AM 2021년 5월 6일
댓글: Ángel AM 2021년 5월 6일
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
Jan 2021년 5월 6일
편집: Jan 2021년 5월 6일
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

추가 답변 (1개)

Alan Stevens
Alan Stevens 2021년 5월 6일

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by