Optimization Toolbox    

Nonlinear Equations with Finite-Difference Jacobian

In the preceding example, the function bananaobj evaluates F and computes the Jacobian J. What if the code to compute the Jacobian is not available? By default, if you do not indicate that the Jacobian can be computed in the objective function (using the Jacobian parameter in options), fsolve, lsqnonlin, and lsqcurvefit instead use finite differencing to approximate the Jacobian. This is the default Jacobian option.You can select finite differencing by setting the Jacobian parameter to 'off' in optimset.

This example uses bananaobj from the preceding example as the objective function, but sets the Jacobian parameter to 'off' so that fsolve approximates the Jacobian and ignores the second bananaobjoutput. It accepts the fsolve default 'off' for the LargeScale parameter, and the default nonlinear equation medium-scale algorithm 'dogleg':

The example produces the following output:

The finite-difference version of this example requires the same number of iterations to converge as the analytic Jacobian version in the preceding example. It is generally the case that both versions converge at about the same rate in terms of iterations. However, the finite-difference version requires many additional function evaluations. The cost of these extra evaluations might or might not be significant, depending on the particular problem.


  Nonlinear Equations with Analytic Jacobian Multiobjective Examples