How could I fix the error "Out of memory with ode45" ?

5 views (last 30 days)
Hello!
I am trying to solve a system of ODEs based on Lotka-Volterra Predator-prey model with many variables. I got an error as follows.
" Out of memory. The likely cause is an infinite recursion within the program.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); "
Thank you.

Answers (1)

Steven Lord
Steven Lord on 1 Jul 2020
Edited: Steven Lord on 1 Jul 2020
My suspicion is that you're calling ode45 with a function handle as input from inside the function that you're passing into ode45.
function yprime = example557812(t, y)
sol = ode45(@example557812, [0 10], 1);
yprime = y;
end
In this case example557812 calls ode45 which calls example557812 which calls ode45 which calls example557812 which calls ode45 which calls example557812 which calls ode45 which calls ...
Split the function that calls ode45 and the function called by ode45 into two separate functions. The function called by ode45 can be a local function in the file (it doesn't have to be its own file) but it shouldn't be the same as the function that calls ode45.
function sol = example557812_take2
sol = ode45(@fun, [0 10], 1);
plot(sol.x, sol.y)
end
function yprime = fun(t, y)
yprime = y;
end

Tags

Products

Community Treasure Hunt

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

Start Hunting!