Ordinary Differential Equations Help

1 visualización (últimos 30 días)
Leah Powell
Leah Powell el 11 de Abr. de 2015
Comentada: Star Strider el 11 de Abr. de 2015
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

Respuesta aceptada

Star Strider
Star Strider el 11 de Abr. de 2015
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.
  2 comentarios
Leah Powell
Leah Powell el 11 de Abr. de 2015
Thank you very much that is easier to understand than I thought. I just wanted to know why is there a *0.5 at the end of y0, and what do the values in tspan (0,1,100) stand for?
Thanks again, Leah
Star Strider
Star Strider el 11 de Abr. de 2015
My pleasure.
The 0.5 value at the end of ‘y0’ creates a vector of values for it that are [0.5; 0.5; 0.5]. (It multiplies all the elements in the [1; 1; 1] vector by 0.5.) I was experimenting with initial conditions, and it is easier to change one value than three.
This line:
tspan = linspace(0, 1, 100);
creates a vector of 100 linearly-spaced (equally-spaced) values on the interval (0,1). I chose it arbitrarily to test the code.
Choose the initial conditions, parameter values and time-span that are appropriate to your differential equation system.
Again, my pleasure as always.

Iniciar sesión para comentar.

Más respuestas (1)

KL
KL el 11 de Abr. de 2015
  1 comentario
Leah Powell
Leah Powell el 11 de Abr. de 2015
Thanks for your reply, I will check it now :)

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by