Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

'Maximum recursion limit 500 reached' problem

43 views
Skip to first unread message

Roman Tolmachev

unread,
May 1, 2010, 4:11:23 AM5/1/10
to
Hi guys,
I'll be very thankful if someone helps me with this problem:
"??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer."

I'm trying to solve a system of differential eqs using ode45:
%My code is below
function xdot=fprime(t,x)
global I gCa gK gL VCa VK VL V1 V2 V3 V4 C
I=10^(-4); C=20*10^(-6);
gCa=4.4*10^(-6); gK=8.0*10^(-6); gL=2.0*10^(-6);
VCa=120*10^(-3); VK=-84*10^(-3); VL=-60*10^(-3);
V1=-1.2*10^(-3); V2=18*10^(-3); V3=2*10^(-3); V4=30*10^(-3);
minf=@(V) 0.5*(1+tanh((V-V1)/V2));
ninf=@(V) 0.5*(1+tanh((V-V3)/V3));
tau=@(V) 25/cosh((V-V3)/(2*V4));
timespan=[0 1]; xinit=[-0.08 0];
[t,y]= ode45(@fprime,timespan,xinit);
xdot=zeros(2,1);
xdot(1)=(gCa*minf(x(1))*(x(1)-VCa)+gK*x(2)*(x(1)-VK)+gL*(x(1)-VL))/C+I/C;
xdot(2)=(ninf(x(1))-x(2))/(tau(x(1)));

I use Matlab R2009A Portable.

us

unread,
May 1, 2010, 4:59:05 AM5/1/10
to
"Roman Tolmachev" <tolmach...@gmail.com> wrote in message <hrgnnb$1i1$1...@fred.mathworks.com>...

one of the (few) solutions
- you could extend your recursion limit...
- better, though, reconsider your code...

nv=700;
set(0,'recursionlimit',nv);

us

Roman Tolmachev

unread,
May 1, 2010, 5:15:19 AM5/1/10
to
> one of the (few) solutions
> - you could extend your recursion limit...
> - better, though, reconsider your code...
>
> nv=700;
> set(0,'recursionlimit',nv);
>
> us

Thank you, however, I tried 1000 as a recursion limit, and the same error. About second advice, how should I change the code? Somebody says to put ode in another m-file, but I dont feel it will work...

David Young

unread,
May 1, 2010, 5:15:20 AM5/1/10
to
A good strategy to fix a problem like this is to go through your code line by line, writing down what happens at each step.

At a quick glance, and missing out the computations, it looks like this happens when you run your code:

something calls fprime
fprime calls ode45
ode45 calls fprime
fprime calls ode45
ode45 calls fprime
fprime calls ode45
ode45 calls fprime
fprime calls ode45

My recursion limit is 7 and now its been exceeded so I'll have to stop here - but hopefully the solution is now obvious.

Steven Lord

unread,
May 3, 2010, 10:33:03 AM5/3/10
to

"Roman Tolmachev" <tolmach...@gmail.com> wrote in message
news:hrgnnb$1i1$1...@fred.mathworks.com...

> Hi guys,
> I'll be very thankful if someone helps me with this problem:
> "??? Maximum recursion limit of 500 reached. Use
> set(0,'RecursionLimit',N)
> to change the limit. Be aware that exceeding your available stack space
> can
> crash MATLAB and/or your computer."
>
> I'm trying to solve a system of differential eqs using ode45:
> %My code is below
> function xdot=fprime(t,x)

*snip most of the "guts" of fprime*

> [t,y]= ode45(@fprime,timespan,xinit);

See Q4.15 in the newsgroup FAQ. Move this call to ODE45 OUT of fprime
itself.

--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


0 new messages