Error: Maximum recursion limit of 500 reached.

2 views (last 30 days)
Hello all,
I am trying to run following code in MATLAB;
function dX_dt = Model(t, x)
% Initial states
Sno3_0 = 0.62;
SacT_0 = 0.6;
Xdn_0 = 0.2;
x0 = [Sno3_0; SacT_0; Xdn_0];
x = [0;0;0];
% Naming the states
Sno3 = x(1);
SacT = x(2);
Xdn = x(3);
% Model Parameters
tFinal = 120;
HRT = 6;
D = 0.166;
Sno3_in = 10;
Sac_in = 11;
X_in = 0;
%Yxac = 0.75;
Yxac = 0.3075;
%Yno3ac = 0.88;
Yno3ac = 0.9152;
pKa_ac = 4.777;
%ka_ac = 1.67109E-05;
pH = 5;
%H = 0.00001;
qmax = 0.914634146;
Ks_ac = 0.024;
Ks_no3 = 0.248;
% Algebric
Sach = SacT*10^(-pH)/(10^(-pKa_ac)+10^(-pH));
% Rate equation
Mac = (Sach/(Ks_ac+SacT));
Mno3 = (Sno3/(Ks_no3+Sno3));
qSac = qmax*min(Mac,Mno3);
% Model balances
dXdn_dt = -D*Xdn+qSac*Xdn*Yxac;
dSno3_dt = D*(Sno3_in-Sno3)-qSac*Yno3ac*Xdn;
dSacT_dt = D*(Sac_in-SacT)-qSac*Xdn;
% Returning the vector of derivatives
dX_dt = [0:0:0];
dX_dt = [dSno3_dt; dSacT_dt; dXdn_dt];
[t,x] = ode45('Model', [0:1:240],x0)
plot(t,x);
However, I am continuously getting the error of;
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Caused by:
Maximum recursion limit of 500 reached.
Kindly help me how to resolve this issue. Thanks

Answers (1)

Steven Lord
Steven Lord on 23 Nov 2021
Do not call ode45 with 'Model' as the first input from within Model.m itself. Move the ode45 call (and the code necessary to create the inputs with which you call ode45) to a separate file or run them in the Command Window.

Community Treasure Hunt

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

Start Hunting!