Is my attempt for simulation SIR model correct?
Show older comments
Hello
I'm trying to recreate results from a given paper in order to understand more. However, my attempt is different a little bit from the picture in the paper, so I'm wondering what's wrong? This my attempt
>> r=0.95
gamma=0.4
beta=r*gamma
mu=0.15
N=10000
f = @(t,x) [mu*N-mu*x(1)-beta*x(1)*x(2)/N;beta*x(1)*x(2)/N -gamma*x(2)-mu*x(2);gamma*x(2)-mu*x(3)]
[t,xa]=ode45(f,[0 100], [5000 5000 0]);
plot(t,xa(:,1),'g')
hold on
plot(t,xa(:,2),'r')
plot(t,xa(:,3),'b')
set(gca,'XTick',[0:5:100])
set(gca,'YLim',[0 10000])
pbaspect([2 1 1])
xlabel('time(days)')
ylabel('Number of Susceptible,Infected and Recovered Individuals')
legend('Number of Susceptible Individuals', 'Number of Infected Individual','Number of Recovered Individuals')
hold off
Answers (1)
Star Strider
on 25 Sep 2017
I’m guessing here.
Assuming that you implemented the ODE function correctly, differences in the ODE solver used could lead to different results. (I’ve seen this before here on MATLAB Answers, and have encountered it in my own research.) Many use generic ‘free’ solvers or unsophisticated solvers. The MATLAB solvers are the most robust and produce the best results, so I would trust your results over published results using less-sophisticated solvers.
Also, for best results, vectorise your functions to use element-wise operations on all multiplication, division, and exponentiation operations, unless you specifically intend to use matrix operations:
f = @(t,x) [mu.*N-mu.*x(1)-beta.*x(1).*x(2)./N; beta.*x(1).*x(2)./N -gamma.*x(2)-mu.*x(2); gamma.*x(2)-mu.*x(3)];
Categories
Find more on Programming 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!