Why does my ODE solver go slow when I specify the Jacobian

4 views (last 30 days)
Gideon Idumah
Gideon Idumah on 26 Nov 2021
Commented: Walter Roberson on 26 Nov 2021
I have a code that uses ode15s to solve a stiff ode system. The RHS is of size 32. I realized that when I specify the Jacobian using odeset, the code is very very slow and run for hours without completion (I track the time step it takes). However, if I don't specify the Jacobian, the code runs in less than a minute. Here is the ODE code.
options = odeset('BDF','on','MaxOrder',2,'Jacobian',@(t,u) MyJacobian(t,u,MM_params, RHS_params));
[time,u_sol] = ode15s(@(t,u) RHS(t,u, MM_params, RHS_params), 0:0.4:tspan, U_init, options);
Here, the Jacobian depends on time (t) and the solution (u). I will think specifying the Jacobian will give a more accurate and faster result.
I will appreciate comments and feedbacks on what I am doing wrong. Thanks
  1 Comment
Walter Roberson
Walter Roberson on 26 Nov 2021
Exact calculation methods are not always faster.
For example, one can imagine situations in which one could calculate the "exact" value of a parameter by doing a nonlinear curvefitting to fit an equation... but that at the same time, in practice, a bisection method might get to the same level of accuracy in a small number of faster calls.
So generalities, without seeing the code or knowing the shape of the function: what you describe is certainly possible.

Sign in to comment.

Answers (0)





Community Treasure Hunt

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

Start Hunting!