odeJacobian
Supplies the Jacobian of an ODE to an ode object.
Category: Other public functions: funfun
Syntax
J = odeJacobian(Jacobian=fcn)
Creates a Jacobian definition from a function @(t, y) returning the matrix of derivatives.
J = odeJacobian(Jacobian=fcn, SparsityPattern=S)
Also declares which entries can be nonzero.
Description
Implicit solvers such as ode15s solve a nonlinear system at every step and need the Jacobian of the right-hand side. If it is not given, it is estimated by finite differences, which costs extra evaluations. Giving the exact Jacobian makes stiff problems faster and more reliable. For large systems the sparsity pattern lets the solver skip entries that are always zero.
Input arguments
Jacobian- Function handle, or a constant matrix, with the derivative of the right-hand side with respect to the state.
SparsityPattern- Sparse logical matrix marking the entries that may be nonzero.
Output arguments
J- An
odeJacobianobject, assigned to theJacobianproperty of anodeobject.
Example
Exact Jacobian for a stiff solver
J = odeJacobian(Jacobian=@(t, y) -1);
f = ode(ODEFcn=@(t, y) -y, InitialValue=1, Jacobian=J, Solver='ode15s');
sol = solve(f, 0, 1);
fprintf('%.3f\n', sol.Solution(end))
Output
0.368