Ordinary Differential Equations Help

조회 수: 2 (최근 30일)
Leah Powell
Leah Powell 2015년 4월 11일
댓글: Star Strider 2015년 4월 11일
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

채택된 답변

Star Strider
Star Strider 2015년 4월 11일
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
Leah Powell
Leah Powell 2015년 4월 11일
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 2015년 4월 11일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KL
KL 2015년 4월 11일
  댓글 수: 1
Leah Powell
Leah Powell 2015년 4월 11일
Thanks for your reply, I will check it now :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by