problem in simulating an epidemic model using ode45
显示 更早的评论
I am trying to solve and simulate an epidemic model using the guidelines provided by an online tutorial: Here is the function i have defined:
function ypsir = ypsir(t,y) a = 0.25; b = 0.000000908; k = 6; q = 22.02; m = 0.012; p = 0.45; l = 0.25; r = 0.14; ypsir(1) = q - m*y(1)-b*y(1)*y(5)+a*y(4); ypsir(2) = ((1-p)*b*y(1)*y(5))-((m+l)*y(2)); ypsir(3) = (b*p*y(5)*y(1))-((m+r)*y(3))+(l*y(2)); ypsir(4) = (r*y(3))-((m+a)*y(4)); ypsir(5) = ((y(5)/(y(5)+1000))*(exp(10*(y(2)+y(3)))))-(b*k*y(1)*y(5)) ypsir = [ypsir(1) ypsir(2) ypsir(3) ypsir(4) ypsir(5)]';
and i use the following m file to call the above function and plot my graphs:
clear; to = 0; tf = 50; yo = [200 20 20 10 1000000]; [t y] = ode45('ypsirtry',[to tf],yo); plot(t,y(:,1),t,y(:,2),t,y(:,3),t,y(:,4)) xlabel('time') ylabel('susceptible, infected, recovered')
but i am only getting straight lines... seems like the ode45 is not working and the graphs are being plotted for the initial values stated.
Can someone pls help
回答(1 个)
David Sanchez
2013-5-10
I tested your code and they are not straight lines, zoom in the plot to see it. Also, check the name of your function
function ypsir = ypsirtry(t,y)
....
...
Then
clear;
to = 0;
tf = 50;
yo = [200 20 20 10 1000000];
[t y] = ode45(@(t,y) ypsirtry(t,y),[to tf],yo);
plot(t,y(:,1),t,y(:,2),t,y(:,3),t,y(:,4))
xlabel('time')
ylabel('susceptible, infected, recovered')
Are you sure your system is what it should be?
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!