Ordinary Differential Equations Help

2 Ansichten (letzte 30 Tage)
Leah Powell
Leah Powell am 11 Apr. 2015
Kommentiert: Star Strider am 11 Apr. 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

Akzeptierte Antwort

Star Strider
Star Strider am 11 Apr. 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 Kommentare
Leah Powell
Leah Powell am 11 Apr. 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 am 11 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KL
KL am 11 Apr. 2015
  1 Kommentar
Leah Powell
Leah Powell am 11 Apr. 2015
Thanks for your reply, I will check it now :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by