Why does my ODE solver go slow when I specify the Jacobian
4 views (last 30 days)
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