MATLAB: Numerical solution of differential equations with MuPAD uses too much RAM

differential equationsmemorymupadnumeric::odesolvenumerical resolutionram

I need to solve numerically several differential equations (the same set with different parameters each time). I created a MuPAD notebook file (.mn) which solves the equations with numeric::odesolve. I evaluate this file from MATLAB within a for loop, to solve the equations with the different set of parameters each time.
It works, but the problem is that it needs too much RAM, more than available.
I've tried closing the MuPAD file every time, or every few times, and it helps a little. However, MATLAB is still using a lot of RAM and I can't figure out what for. I've narrowed it down to the interaction of MATLAB and MuPAD, but clearing the variables that I'm passing to MuPAD after solving the equations each time, or the function handler is not the key (or even every single variable with clear all). The only way of clearing all that RAM is exiting MATLAB and starting it again.
Does anyone know what that memory is used for and how to clear it once it's not needed anymore? I can't think of anything apart from running the code for a few sets of parameters, saving the results, exiting, starting, running it for a few other sets, etc. and then performing the rest of calculations.

Best Answer

Is there a particular reason for you not to use one of the MATLAB numeric solvers, such as ode45?
You can use the Symbolic Math Toolbox odeToVectorField and matlabFunction functions to create an anonymous function to use with the numeric solvers. This works for linear and nonlinear equations, and in all likelihood, you would not encounter the memory problems.