From: Roman Tolmachev on
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.
From: us on
"Roman Tolmachev" <tolmachevroman(a)gmail.com> wrote in message <hrgnnb$1i1$1(a)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)
> 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.

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

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

us
From: Roman Tolmachev on
> 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...
From: David Young on
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.
From: Steven Lord on

"Roman Tolmachev" <tolmachevroman(a)gmail.com> wrote in message
news:hrgnnb$1i1$1(a)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
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ