Ordinary Differential Equations Help
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!