Recursion Limit Error in ODE45

1 view (last 30 days)
Eric
Eric on 2 Nov 2011
I almost have the problem solved but my seoncd to last line keeps giving me an error saying "Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)to change the limit. I have changed the time span and initial conditions but that did not correct the problem.
function dy = focaultPendulum(t,y)
% define your constants
g = 9.81; % acceleration of gravity (m/sec^2)
l = 60; % pendulum length (m)
b = .2; x = b; % initial x coordinate (m)
y = b/2; % initial y coordinate (m)
xdot = 0; % initial x velocity (m/sec)
ydot = 0; % initial y velocity (m/sec)
Omega = 2*pi/86400; % Earth's angular velocity of rotation about its axis (rad/sec)
lambda = 30/180*pi; % latitude in (rad) P = Omega*sin(lambda); C=(g/l)^2;
xddot = -C*x + 2*P*ydot; %Equation of motion 1
yddot = -C*y - 2*P*xdot; %Equation of motion 2
u = xdot;
udot = xddot;
v = ydot;
vdot = yddot;
udot = -C*x + 2*P*v;
vdot = -C*y - 2*P*u;
t0 = 0; %time initial tf = 8640;
%time final i.e. seconds in a day xy0 = [b b/2 0 0];
%initial conditions dy(1) = xdot;
dy(2) = udot;
dy(3) = ydot;
dy(4) = vdot;
dy(:);
[t,dy] = ode45(@focaultPendulum,[t0,tf], xy0);
% plot(t,dy(:,1),t,dy(:,3))

Answers (1)

Walter Roberson
Walter Roberson on 2 Nov 2011
Your code is all inside your function focaultPendulum . Inside that function, you call ode45 and tell ode45 that for each step, it should call focaultPendulum to get an answer. So it does that, and at the end of the focaultPendulum there is a call to ode45 that says call focaultPendulum to get the answer for the step. So it does that, and at the end of the focaultPendulum there is a call to ode45 that says call ....
As ode45 is always called unconditionally within focaultPendulum and it calls focaultPendulum unconditionally, this sequence only ends when MATLAB gives up because you have made too many recursions.
What you should be doing is having two routines, one of which only calculates one step, and the other of which sets up the initial conditions and calls ode45 telling it to call the other routine.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!