1

I am trying to do exactly what has been explained here: How solve a system of ordinary differntial equation with time-dependent parameters (part 2).

Here is my code. I have no idea where I'm going wrong.

function shi = shitry(t,y,b,bt)
b = interp1(bt, b, t)
a = 0.25; %loss of immunity rate
% b = 0.0002; %infectivity rate
q = 10; %population renewal
m = 0.012; %death rate
r = 0.14;  %recovery rate
shi(1) = q - m*y(1)-b*y(1)*y(2)+a*y(3);
shi(2) = (b*y(1))- (m + r)*y(2);
shi(3) = (r*y(2))-((m+a)*y(3));
shi = shi(:);
end

That's the function defined above.

bt = [5 9 12 17 19 24 28 27 22 17 10 7];
b = 0.00002*bt;

tspan = linspace(0, 12, 50);
yo = [200000 150 0];
[tv,Yv] = ode45(@(t,y) shitry(t, y, bt, b), tspan, yo);
plot(tv,Yv(:,1),'+',tv,Yv(:,2),'x',tv,Yv(:,3),'o');

When I run the codes, I get the following errors:

Error using griddedInterpolant The grid vectors are not strictly monotonic increasing.

Error in interp1 (line 191) F = griddedInterpolant(X,V,method);

Error in shitry (line 2) b = interp1(bt, b, t)

Error in @(t,y)shitry(t,y,bt,b)

Error in odearguments (line 88) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in shigella (line 23) [tv,Yv] = ode45(@(t,y) shitry(t, y, bt, b), tspan, yo);

Community
  • 1
  • 1
Ojaswita
  • 83
  • 10
  • What is the question here? You post a link you are following and two pieces of code, but no question. – Adriaan Sep 01 '15 at 20:57
  • 1
    Minor comment. I misread your function name... especially the first four letters. Perhaps you should change how your function is named to something else. – rayryeng Sep 01 '15 at 21:10
  • 1
    Why are you passing `b` then `bt` in your function definition, but passing `bt` then `b` in your `ode45` call? You need to edit your question to explain what you mean by "going wrong." Provide any error messages and/or describe exactly what doesn't work and why you think so. – horchler Sep 01 '15 at 22:22
  • Have edited my question with the error messages. I would like to get a new value of b on each time step, and Im not able to get it. – Ojaswita Sep 03 '15 at 06:18
  • Did you ever solve the problem? – Dan Powers Nov 06 '16 at 06:05
  • Yes I did... Quite sometime back... I will try to retrieve the code and repost it here for the benefit of others – Ojaswita Mar 26 '19 at 13:03

0 Answers0