# Error with ODE and nargin

1 view (last 30 days)
Divya Noonela on 18 Sep 2020
Commented: Divya Noonela on 23 Sep 2020
Hello, can anyone help me out with this.?
function xdot = glucoseff(t,x)
p1=0.028735;
p2=0.028344;
p3=5.0353e-5;
gb=200;
ib=0;
n=0.10;
vi=12;
a=0:0.1:10
ug=exp(-a);
g=x(1);
y=x(2);
i=x(3);
%
%odes
%
dgdt=(-p1*g)-(t*g)+(p1*gb)+ug;
dydt=(-p2*y)+(p3*i)-(p3*ib);
didt=(-n*i)+ui/vi;
xdot = [dgdt; dydt; didt];
end
clc;
x0=[200;0;10];
[t,x] = ode45('glucoseff',[0 10],0);
plot(x(:,1));
plot(x(:,2));
plot(x(:,3));
I don't understand the error :
Error using nargin
Error: File: glucoseff.m Line: 1 Column: 1
Function definitions are not permitted in this context.
Error in odearguments (line 60)
if (nargin(ode) == 2)
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in glucose_main (line 4)
[t,x] = ode45('glucoseff',[0 10],0);

Alan Stevens on 18 Sep 2020
1. You need to define ui within glocoseff.
2. Do you really want ug to be a vector the same size as a; or do you want it to take on the different a values one at a time?
Vasishta Bhargava on 19 Sep 2020
% if true
% code
%end
[t,x] = ode45(@glucoseff,[0 10],x0)
Divya Noonela on 23 Sep 2020
ug is a vector of same size of a

Vasishta Bhargava on 19 Sep 2020
% if true
% code
%end
[t,x] = ode45(@glucoseff,[0 10],x0)