Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Derivative Computation

Large CCD problems typically require gradient-based optimization: objective gradients, constraint Jacobians, and sometimes Lagrangian Hessians.

Finite differences, complex step, analytic derivatives, automatic differentiation, and sensitivity methods compared by accuracy and effort.

Major derivative-computation options for nonlinear programming.

Finite differences

FziF(z+hei)F(z)h\frac{\partial F}{\partial z_i}\approx\frac{F(\mathbf{z}+h\mathbf{e}_i)-F(\mathbf{z})}{h}

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,

FziImF(z+ihei)h.\frac{\partial F}{\partial z_i}\approx \frac{\operatorname{Im}F(\mathbf{z}+ih\mathbf{e}_i)}{h}.

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,

ζk=xk+1xkhk2(fk+fk+1),\boldsymbol{\zeta}_k=\mathbf{x}_{k+1}-\mathbf{x}_k-\frac{h_k}{2}(\mathbf{f}_k+\mathbf{f}_{k+1}),

representative blocks are

ζkxk=Ihk2fx,k,ζkxk+1=Ihk2fx,k+1,\frac{\partial\boldsymbol{\zeta}_k}{\partial\mathbf{x}_k}=-I-\frac{h_k}{2}\mathbf{f}_{x,k}, \quad \frac{\partial\boldsymbol{\zeta}_k}{\partial\mathbf{x}_{k+1}}=I-\frac{h_k}{2}\mathbf{f}_{x,k+1},

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

ED=dimplementeddreference2max(1,dreference2).E_D=\frac{\|\mathbf{d}_{\mathrm{implemented}}-\mathbf{d}_{\mathrm{reference}}\|_2} {\max(1,\|\mathbf{d}_{\mathrm{reference}}\|_2)}.

Derivative errors can cause slow convergence, false convergence, or convergence to the wrong point.

Activity 7.4: Analytical Hermite--Simpson Jacobian

Activity 7.5: Derivative Verification for a Shooting Formulation