Derivative Computation
Large CCD problems typically require gradient-based optimization: objective gradients, constraint Jacobians, and sometimes Lagrangian Hessians.
Major derivative-computation options for nonlinear programming.
Finite differences¶
is easy to implement but balances truncation against cancellation and may require one evaluation per column. Sparse coloring perturbs structurally independent columns together.
Before coloring can be applied, the solver needs to know which functions depend on which variables. One practical dependency-detection technique evaluates each constraint or objective function once with a single input component set to NaN; IEEE floating-point arithmetic propagates NaN through every expression that actually depends on that component, so a single perturbed evaluation reveals an entire row of the first-derivative sparsity pattern. Repeating this for each input component (or exploiting problem structure to batch several at once) yields the full Jacobian sparsity pattern with a small number of extra function evaluations; squaring the resulting 0/1 pattern gives a conservative estimate of the Hessian sparsity. This dependency map is what lets sparse finite-differencing compute only the structurally nonzero derivative entries, and it is what makes a single transcription implementation usable with both quasi-Newton NLP solvers, which need only the gradient and constraint Jacobian, and full-Newton solvers, which additionally need the sparse Lagrangian Hessian.
Complex-step differentiation¶
For analytic code,
It avoids subtractive cancellation and is excellent for verification, provided complex numbers propagate correctly and nonanalytic operations are avoided.
Analytic derivatives¶
For a trapezoidal defect,
representative blocks are
with analogous control blocks. These formulas expose local sparsity directly.
Automatic differentiation and sensitivities¶
Automatic differentiation applies the chain rule to code and can provide machine-precision sparse Jacobians and Hessians. Forward mode suits few independent variables; reverse mode suits scalar outputs with many inputs.
Shooting derivatives often use direct or adjoint sensitivities. Direct sensitivities propagate one system per parameter; adjoints can be efficient for many parameters and few scalar outputs.
Verification¶
Compare implemented derivatives against complex step or careful finite differences at random points. A normalized discrepancy is
Derivative errors can cause slow convergence, false convergence, or convergence to the wrong point.
Activity 7.4: Analytical Hermite--Simpson Jacobian¶
Activity 7.4: Analytical Hermite--Simpson Jacobian
Consider the nonlinear, parameter-dependent system
where is a plant-design variable. For interval , define
and
The Hermite--Simpson defect is
Derive
Assemble the Jacobian sparsity pattern for intervals.
Determine the exact number of nonzero entries.
Explain why the column associated with is globally dense while the state and control blocks remain locally sparse.
Verify the analytical Jacobian using complex-step differentiation.
Activity 7.5: Derivative Verification for a Shooting Formulation¶
Activity 7.5: Derivative Verification for a Shooting Formulation
Consider
Parameterize using piecewise-constant values:
Minimize
Derive the forward-sensitivity equations
Derive the gradient .
Compute the gradient using:
forward finite differences;
central finite differences;
complex-step differentiation; and
sensitivity equations or automatic differentiation.
Perform a directional-derivative test using a random normalized vector .
Plot derivative error for step sizes from 10-2 to 10-14.
Explain the truncation-error and cancellation-error regions in the resulting plot.