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);