MATLAB: Why do i keep getting this error:attempted to access f1(0,200); index must be a positive integer or logical

indexpositive

Hi there,
Could someone please explain to me why i keep getting this error: Attempted to access f1(0,200); index must be a
positive integer or logical.
Please find the MATLAB file attached.
function [t,X]=Combined(t,~,Snoe,Sse)
h=0.0006944444; V=10;
tfinal=30;
Qe = 10; Qo = Qe; Y=0.4;
Xo=0; Xe=Xo; u=0.01; S=500; Snoe1=100; Ks=100; Kno=0.5; b=0.02;
%initial conditions
X(1)=200; Sse(1)=5; Snoe(1)=2; t(1)=0;
Snoe=(Qo*Snoe1-Qe*Snoe)/V-(1-Y)/(2.86*Y)*u*(Sse/(Ks+Sse))*(Snoe/(Kno+Snoe))*X;
Sse=(Qo*S-Qe*Sse)/V-u/Y*(Sse/(Ks+Sse))*(Snoe/(Kno+Snoe))*X;
f1=(Qo*Xo-Qe*Xe-V*X/10)/V+u*Sse/(Ks+Sse)+Snoe/(Kno+Snoe)*X-b*X;
for i=1:ceil(tfinal/h)
%update t
t(i+1)=t(i)+h;
%update x
kX1=f1(t(i), X(i));
kX2=f1(t(i)+0.5*h, X(i)+0.5*kX1*h);
kX3=f1(t(i)+0.5*h, X(i)+0.5*kX2*h);
kX4=f1(t(i)+ h, X(i)+ kX3*h);
X(i+1)=f1(i)+(h/6)*(kX1+2*kX2+2*kX3+kX4);
end
end

Best Answer

The problem is obvious:
f1(0,200)
Note that 0 is not a positive integer. Positive integers are integers greater than 0.
Related Question