Fast ODE45 with for-loops
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I have a coupled first order ODE to solve of the form
dy = f(t, x) dx = d(f, x)
which depends on a common parameter which I have to solve for over some range. I can solve the system using ODE45 and a for loops which increments the parameter of interest at each loop, however, this is very slow. Can I avoid solving this problem in loops? Or what is best practice with problems of this type.
0 comentarios
Respuesta aceptada
Marc
el 24 de Ag. de 2013
The infamous double post.... Asked in Newsgroup and answered. Try parfor in the parallel toolbox. If your computer has multicores, you can run 2+ simulations at the same time.
Should help.
Just as a follow up, how long does running ODE45 take? Are we talking seconds or minutes?
Is your function large? I run a simulation with ~3000 odes, using ode15s and this takes between 100-1000 seconds depending on the input parameters. This was a 10x speed up after I used the profiler on my function, NOT on the whole script. Found that I was spending a lot of time passing large structures between functions within the main function. Mostly because I was lazy. Trimmed this up and got much better results.
Add parfor with 12 cores and I was able to get through my DOEs in days rather than weeks.
0 comentarios
Más respuestas (1)
Paul
el 24 de Ag. de 2013
1 comentario
Marc
el 25 de Ag. de 2013
I have compared limex in fortran with ode15s and cvode from Sundials in Matlab and find Matlab to be close to fortran. I did not try to optimize the fortran code, simply tested as is.
You already have available what you are asking. cvode and ida codes, part of the Sundials package have already been "mexed" and packaged for Matlab. This is from Lawrence Livermore National lab. Cvode has some nice features and requires you to format things a bit differently. Not sure if you'll get a speed up.
Limex, lsode, cvode, ida are codes I have compared to ode45 and ode15s over the years and found the Matlab codes to hold up.
So, I think you are stuck from the integrator standpoint.
My only comment would be try running your parameter maybe 5 times, say at the min, max and three intermediate points to see if you can minimize that 25,000 runs. Maybe there is something special about your system, but I tend to believe if you pick say 32 points and randomize the runs, you should get a good enough picture of what is going on.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!