ODE solver with too many function calls

Hello,
I am using an Ode solver to simulate a mechanical system with a mass and a spring. Besides the spring and an external force there is a nonlinear force acting on the system. Each computation takes around 4 ms.
When im am simulating the exact same system in Matlab, the ode23t needs around 200 function evaluations.
In Julia all solver I tried (non stiff and stiff solvers) are calling the ode_function at least 2200 times. The one performing the best is the Rosenbrock23.
I am using the same tolerances in matlab as in julia. Is there a solver option I am missing?
I am also using the same initial step size.

Thanks for your help.

Is it exactly the same ODE? Did you check at random values? Can you share your validation?

I am sorry. I didnt saw a typo in the computation of the jacobi for 1 week.
Thanks for your answer

1 Like

Hi, i have a follow up problem to my last one above.
I compared most of the stiff solvers avaible against the ode15s in Matlab. As my equation gets more and more stiff, the julia solvers still have at least twice as much function calls.
If I reduce the error tollerance, the solution i obtain is not acceptable. Since the function calls are expensive I really would like to reduce them.

I checked the ode_function and the ode_jacobian with random inputs against my Matlab code. The results are exactly the same.
A list of the solvers I tried:

  • Some SDIRKT Methods ( but my jacobian is changing alot)
  • RadauIIA3 and RadauIIA5
  • ROS3P
  • Rodas3,Rodas4, Rodas4P2, Rodas5P, Rodsa4P and 5P
  • Rosenbrock23

Thanks for your time. Tell me if you have an idea or you need some more informations.

1 Like

What about QNDF and FBDF? These are the solvers most similar to ode15s. In general the stiff solvers that are worth trying first are Rosenbrok23, Rodas5P, QNDF, and FBDF.

Ahh yes. I tried them. For the same tolerances I get 4 times as many evals. And the result in Matlab is even more accurate.
If i am reducing the maximum step size I am getting compareable results.
But this should not be the way.

You probably shouldn’t be touching the maximum step sizes (and reducing the maximum step size should strictly increase the number of evaluations).

I meant, if I am using a smaller max. step size I can reducde the tolerance.
But as you said, this is no solution^^

how are you measuring accuracy? two different solvers with the same tolerance can yield very different accuracy.

And there’s no code to share?

I compared the results to a Simultion with a lot smaller tolerances.

Its hard, since the computation of the nonlinear force is done in many files. I also dindt wrote all the parts by my selfe. So I am not sure if I am allowed to share them public.
I could share the rest if its helpfull.

Well it’s really hard to help if there’s no code to compare. But the #1 issue always tends to be that the translation is not 1-1. If you run all of the functions with random (u,p,t) do you get the same exact answer from MATLAB and Julia? In almost all cases like this, I’ve found that to be false, so that’s the first thing I would look into detail with.

Other than that ode23t is very different from solve of the solvers you’re discussing here. Did you try the Trapezoidal counterpart? L-stability is good for “most” equations, but not ones for which the dampening is not beneficial. In which case, the reversibility (and “close to symplecticness”) can be beneficial. So it’s good to try methods that are similar to what you’ve seen work well before.

Lastly, you may want to watch this video which highlights some of the most common issues people have when translating, particularly from MATLAB:

1 Like

Hi @c_sell !

Just one question: are you simulating the system using a .m file or simulink?

In matlab I am simulating using a .m file

Thanks for your answer. I used in Matlab the ode15s. The function outputs are the same for random inputs.
I have already seen your video before and I tried the steps there.

Ok, many many years ago, when @ChrisRackauckas helped me a lot by adding amazing features to DifferentialEquations.jl ecosystem, I was doing exactly the same comparison. I see results similar to yours, but it was caused by simulink. It seems it were automatically changing the tolerances, yielding less evaluations. However, everything was very similar when using .m and the function ode45.

1 Like

If you used ode15s, then you should try QNDF and FBDF which are the most similar (QNDF should be fairly similar).

1 Like

Thats what I tried.

Interesting. With or without autodiff? Does the difference there matter? Are there complex valued variables? And the function is exactly the same on random values?