The SIR model has been developed in the past years to simulate the spread of a virus over time. The script includes a brief introduction, in which the model is presented, and the code to run the simulation of the epidemic over time. Two cases are analysed: one without immunity loss, where recovered individuals don't get infected again, and one with immunity loss.
Giovanni Valentini (2020). SIR Epidemic Spread Model (https://www.mathworks.com/matlabcentral/fileexchange/75100-sir-epidemic-spread-model), MATLAB Central File Exchange. Retrieved .
It might be better to scale the model by population size N.
% Equations of the model
dS = (-beta*I(tt)*S(tt)/N + delta*R(tt)) * dt;
dI = (beta*I(tt)*S(tt)/N - gamma*I(tt)) * dt;
dR = (gamma*I(tt) - delta*R(tt)) * dt;
Easy to use code with no apparent bugs