Problems in the implementation of ODE45 in an epidemiological problem SIR

Hello community, today I am trying to verify how my SIR epidemiologist model applied to yellow fever is behaving with some data entered. In this case in my program I took S = susceptible, I = infected, R = recovered, N = mosquitoes not carrying the virus and P = mosquitoes carrying the virus, using the ODE45 function. In this case I started with a population of 99 susctiveis people, one infected, one non-carrier mosquito and three carriers, in a time period of 0 to 50 days. That's all just to test if the program would run.
But when compilo I get the following error and I do not know how to fix it.
Undefined function or variable 'R'.
Error in ypsir (line 13)
ypsir(1) = sigmah*R - muh*S - betah*P*S + lambdah*(I+ R + S);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ypsir_main (line 5)
[t y] = ode45('ypsir',[to tf],yo);
I know I'm missing out on something that may be relatively easy, but I'm starting to program now, so it may be that some technical terms that are said in the speech will not be understood, please try to be a little didactic.
The codes used are First part function ypsir =ypsir(t,y) betah = .01; muh = 0.01; sigmah = 0.05; alphah = 0.06; deltah = 0.05; mui = 0.07; mum = 0.07; betai = 0.03; lambdai = 0.06; lambdai = 0.5;
ypsir(1) = sigmah*R - muh*S - betah*P*S + lambdah*(I+ R + S);
ypsir(2) = -deltah*I - I*(alphah + muh) + betah*P*S;
ypsir(3) = deltah*I - sigmah*R;
ypsir(4) = -mui*N - mum*N1 - betai*I*N + lambdai*(N + P)*(1 - (N + P)/k);
ypsir(5) = betai*I*N - mui*P - mum*P;
ypsir = [ypsir(1) ypsir(2) ypsir(3) ypsir(4) ypsir(5)];
Second part
clear;
to = 0;
tf =50;
yo = [99 1 0 1 3];
[t y] = ode45('ypsir',[to tf],yo);
plot(t,y(:,1),t,y(:,2),t,y(:,3),t,y(:,4),t,y(:,5))
title('First Model of Yellow Fever')
xlabel('time')
ylabel('susceptible, infected, recovered,Mosquito Non-carrier, Mosquito
Carrier')

3 Comments

Could you include the code you are using ?
I looked at my code and realized a bug and fix it, but still, it still gives error! Can anyone help? Please find attached the codes with the modifications.
And the error now is this
>> ypsir_main
Error using feval
Undefined function 'ypsirtry' for input arguments of type
'double'.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options,
varargin);
Error in ypsir_main (line 6)
[t y] = ode45('ypsirtry',[to tf],yo);

Sign in to comment.

 Accepted Answer

function ypsir = ypsirtry(t,y)
betah = .01;
muh = 0.01;
sigmah = 0.05;
alphah = 0.06;
deltah = 0.05;
mui = 0.07;
mum = 0.07;
betai = 0.03;
lambdai = 0.06;
lambdai = 0.5;
ypsir = zeros(5,1);
ypsir(1) = sigmah*y(3) - muh*y(1) - betah*y(1)*y(5) + lambdah*(y(2)+ y(3) + y(1));
ypsir(2) = -deltah*y(2) - y(2)*(alphah + muh) + betah*y(5)*y(1);
ypsir(3) = deltah*y(2) - sigmah*y(3);
ypsir(4) = -mui*y(4) - mum*y(4) - betai*y(2)*y(4) + lambdai*(y(4) + y(5))*(1 - (y(4) + y(5))/k);
ypsir(5) = betai*y(2)*y(4) - mui*y(5) - mum*y(5);
Best wishes
Torsten.

3 Comments

Hello,
thank you very much for the time you spent in replying, I changed some things in the code and your answer helped a lot. I put the code to run and it does not work for 20 minutes. I put small data just to help. Did I do something wrong or will the code actually be delayed due to the equations themselves? Please find attached the codes, if you want to take a look, to indicate why this delay. From this I thank you very much for the help you gave me. Sorry English, it's not my native language!
Try to use ODE15S instead of ODE45.
Best wishes
Torsten.
All right, thank you! So far he's running!

Sign in to comment.

More Answers (0)

Asked:

GTA
on 15 Mar 2018

Commented:

GTA
on 16 Mar 2018

Community Treasure Hunt

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

Start Hunting!