MATLAB: Ordinary Differential Equations Help

ode45

Hi,
I am currently working on my dissertation and I have to find numerical solutions to the following ODE's using Matlab (with graphs):
dS/dt=μ-λSI-μS dI/dt=λSI-βI-μI dR/dt=βI-μR
I am new to Matlab and can't seem to figure out how to do this. Would it be possible for someone to give me the Matlab codes/instructions I need to find the numerical solutions to these ODE's?
Thanks! Leah

Best Answer

Good Morning, Leah!
This is relatively easy to code, but it helps to have done it before:
% DIFFERENTIAL EQUATION SYSTEM:
% dS/dt=μ-λSI-μS
% dI/dt=λSI-βI-μI
% dR/dt=βI-μR
% MAPPING: S = y(1), I = y(2), R = y(3)
SIR = @(t,y,mu,lam,b) [mu-(lam.*y(2)-mu).*y(1); (lam*y(1)-b-mu).*y(2); b*y(2)-mu*y(3)];
mu = 3; % mu
lam = 5; % lambda
b = 7; % beta
y0 = [1; 1; 1]*0.5;
tspan = linspace(0, 1, 100);
[T,Y] = ode45(@(t,y) SIR(t,y,mu,lam,b), tspan, y0);
figure(1)
plot(T, Y)
grid
legend('S(t)', 'I(t)', 'R(t)', 'Location', 'NW')
You have to define the correct values for ‘mu’, ‘lambda’, and ‘beta’, and your initial conditions, ‘y0’, and the value of ‘tspan’ you want. I chose some random values to be sure the code worked.
Since you’re new at this, I will let you familiarise yourself with the documentation for ode45 to see how it works. Your equations lent themselves to using an anonymous function, so read about as Anonymous Functions as well.