Why does my ODE Solver keep crashing MATLAB?

3 views (last 30 days)
cjenna
cjenna on 24 Jan 2012
I am running the following
function dy = kin1(t, y)
y0 = 0;
yf = 1e-0006;
y = [y0:yf];
dy = 2.1*1e-009 - .4*y - 1.2e-003*y + 2.1e+006*y.^2 - 9.2e-004*y;
t0 = 0; %start time
tf = 100; %end time
[t, y] = ode15s(@kin1, [t0 tf] ,y0); %Solve ODE
And after trying this on several computers with several different versions of Matlab, the program crashes. A few times I got a ??? Maximum recursion limit of 500 reached. Error message.
I feel this should be straight forward as I am following the examples in the Matlab Help pretty closely.

Answers (1)

Walter Roberson
Walter Roberson on 24 Jan 2012
Classic problem. Your function kin1 calls upon ode15s, requesting that ode15s call upon the function kin1 to do work. So ode calls kin1, which then calls ode15s, which calls kin1, which calls ode15s which ...
Your call to the ode functions (and any initialization you need to do) must be in a different function or different file than your routine that does the work (e.g., kin1)

Community Treasure Hunt

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

Start Hunting!