필터 지우기
필터 지우기

ODE45 SIR model problem

조회 수: 5 (최근 30일)
Brilliant Purnawan
Brilliant Purnawan 2020년 11월 19일
댓글: Brilliant Purnawan 2020년 11월 19일
Hi, I'm quite new to MATLAB and recently tried to plot a SIR model using its first order equations, but everytime I tried to use the ODE45 it the equation doesn't seem to change it just gives me a constant plot of the initial value. Can anyone spot a problem? Code is below:
clear all, close all, clc
A = 0.1;
B = 0.3;
tspan = [0:0.01:300];
y0 = [300 0 0];
[t,y] = ode45(@(t,y)odefcn(y,A,B),tspan,y0);
plot(t,y)
function dydt = odefcn(y,A,B)
dydt = zeros(3,1);
dydt(1) = -A*y(2)*y(1);
dydt(2) = A*y(2)*y(1)-B*y(2);
dydt(3) = B*y(2);
end

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 11월 19일
In your initial conditions you have everyone perfectly "healthy" - therefore no one will ever get infected. You have to set at leas some small fraction of your population to infected. That is something like this:
y0 = [299 1 0];
That should kick things off...
HTH
  댓글 수: 1
Brilliant Purnawan
Brilliant Purnawan 2020년 11월 19일
Oh, I see, thanks mate!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by