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.

Sparse NLP Structure and Time Normalization

Direct collocation produces nonlinear programs that are often large but sparse. This structure is one of the main reasons collocation methods are computationally practical.

This section develops:

Review of the Euler NLP

Consider the decision vector

z=[x0x1xKu0u1uK1]T.\boldsymbol{z} = \begin{bmatrix} x_0 & x_1 & \cdots & x_K & u_0 & u_1 & \cdots & u_{K-1} \end{bmatrix}^{\mathsf{T}}.

The defect equations are

ck=xk+1xkh(xk3+uk)=0,c_k = x_{k+1} - x_k - h(-x_k^3+u_k) = 0,

for

k=0,,K1.k=0,\ldots,K-1.

The endpoint constraints are

b1=x0a=0,b2=xKb=0.\begin{aligned} b_1&=x_0-a=0,\\ b_2&=x_K-b=0. \end{aligned}

Local Dependence

Each defect ckc_k depends only on:

xk,xk+1,uk.x_k,\qquad x_{k+1},\qquad u_k.

It does not depend on distant variables such as:

xk+4,uk+6,etc.x_{k+4},\quad u_{k+6},\quad \text{etc.}

This local dependence creates sparsity.

Constraint Jacobian

Define

g(z)=[c0c1cK1b1b2].\boldsymbol{g}(\boldsymbol{z}) = \begin{bmatrix} c_0\\ c_1\\ \vdots\\ c_{K-1}\\ b_1\\ b_2 \end{bmatrix}.

The constraint Jacobian is

Jc=gz.\boxed{ \boldsymbol{J}_c = \frac{\partial\boldsymbol{g}}{\partial\boldsymbol{z}}. }

Its dimensions are

(K+2)×(2K+1).(K+2)\times(2K+1).

Derivatives of One Defect

For

ck=xk+1xk+hxk3huk,c_k = x_{k+1}-x_k+hx_k^3-hu_k,

the nonzero derivatives are

ckxk=1+3hxk2,ckxk+1=1,ckuk=h.\begin{aligned} \frac{\partial c_k}{\partial x_k} &= -1+3hx_k^2,\\ \frac{\partial c_k}{\partial x_{k+1}} &= 1,\\ \frac{\partial c_k}{\partial u_k} &= -h. \end{aligned}

All other partial derivatives of ckc_k are zero.

Sparsity Pattern

The structure is schematically:

x0x1x2xK1xKu0u1u2uK1c0×××c1×××c2×××cK1×××b1×b2×\begin{array}{c|cccccc|ccccc} & x_0&x_1&x_2&\cdots&x_{K-1}&x_K & u_0&u_1&u_2&\cdots&u_{K-1} \\ \hline c_0&\times&\times&&&&&\times&&&&\\ c_1&&\times&\times&&&&&\times&&&\\ c_2&&&\times&\times&&&&&\times&&\\ \vdots&&&&\ddots&\ddots&&&&\ddots&\\ c_{K-1}&&&&&\times&\times&&&&\times\\ \hline b_1&\times&&&&&&&&&&\\ b_2&&&&&&\times&&&&& \end{array}

Only a narrow band of entries is nonzero.

Counting Nonzero Entries

Each defect contributes three nonzeros.

There are KK defects, so:

3K3K

nonzeros arise from the dynamics.

The two endpoint constraints contribute two more.

Therefore,

nnz(Jc)=3K+2.\boxed{ \operatorname{nnz}(\boldsymbol{J}_c) = 3K+2. }

Jacobian Density

The total number of entries is

(K+2)(2K+1).(K+2)(2K+1).

The density is

ρK=3K+2(K+2)(2K+1).\rho_K = \frac{3K+2}{(K+2)(2K+1)}.

As

K,K\rightarrow\infty,
ρK32K0.\rho_K \sim \frac{3}{2K} \rightarrow0.

Thus, the problem becomes increasingly sparse as the mesh is refined.

Why Sparse Structure Matters

A dense treatment stores and processes all entries.

A sparse treatment stores and processes only nonzero entries.

This affects:

For large trajectory-optimization problems, sparse linear algebra is essential.

Sparse NLP Solvers

Modern sparse NLP solvers exploit derivative structure.

Examples include:

MATLAB’s fmincon may be useful for small instructional problems, but large collocation problems benefit from solvers designed explicitly for sparse NLPs.

Why Collocation Naturally Produces Sparsity

A collocation equation on interval kk depends only on variables in or near that interval.

Typical local dependencies include:

(xk,xk+1,uk,uk+1).(\boldsymbol{x}_k,\boldsymbol{x}_{k+1},\boldsymbol{u}_k,\boldsymbol{u}_{k+1}).

Therefore, distant nodes do not interact directly in the Jacobian.

This remains true for many methods:

Multiple States and Controls

For

xRnx,uRnu,\boldsymbol{x}\in\mathbb{R}^{n_x}, \qquad \boldsymbol{u}\in\mathbb{R}^{n_u},

each defect block has dimension nxn_x.

A defect typically depends on:

The Jacobian becomes block sparse and block banded.

Time Normalization

Instead of discretizing directly on

t[t0,tf],t\in[t_0,t_f],

it is convenient to map the domain to

τ[1,1].\tau\in[-1,1].

Define

τ=2tt0tft01.\boxed{ \tau = 2\frac{t-t_0}{t_f-t_0}-1. }

The inverse transformation is

t(τ)=tft02τ+tf+t02.\boxed{ t(\tau) = \frac{t_f-t_0}{2}\tau + \frac{t_f+t_0}{2}. }

Derivation of the Mapping

Starting from

t0ttf,t_0\leq t\leq t_f,

subtract t0t_0:

0tt0tft0.0\leq t-t_0\leq t_f-t_0.

Divide by tft0t_f-t_0:

0tt0tft01.0 \leq \frac{t-t_0}{t_f-t_0} \leq 1.

Multiply by 2 and subtract 1:

12tt0tft011.-1 \leq 2\frac{t-t_0}{t_f-t_0}-1 \leq 1.

Transformation of the Dynamics

The original dynamics are

dxdt=f(t,x,u).\frac{\,\mathrm{d}\boldsymbol{x}}{\,\mathrm{d} t} = \boldsymbol{f}(t,\boldsymbol{x},\boldsymbol{u}).

By the chain rule,

dxdτ=dxdtdtdτ.\frac{\,\mathrm{d}\boldsymbol{x}}{\,\mathrm{d} \tau} = \frac{\,\mathrm{d}\boldsymbol{x}}{\,\mathrm{d} t} \frac{\,\mathrm{d} t}{\,\mathrm{d}\tau}.

From the inverse map,

dtdτ=tft02.\frac{\,\mathrm{d} t}{\,\mathrm{d}\tau} = \frac{t_f-t_0}{2}.

Therefore,

dxdτ=tft02f(t(τ),x(τ),u(τ)).\boxed{ \frac{\,\mathrm{d}\boldsymbol{x}}{\,\mathrm{d}\tau} = \frac{t_f-t_0}{2} \boldsymbol{f} \left( t(\tau),\boldsymbol{x}(\tau),\boldsymbol{u}(\tau) \right). }

Transformation of the Cost

For

J=Φ+t0tfL(t,x,u)dt,J = \Phi + \int_{t_0}^{t_f} L(t,\boldsymbol{x},\boldsymbol{u})\,\mathrm{d} t,

use

dt=tft02dτ.\,\mathrm{d} t = \frac{t_f-t_0}{2}\,\mathrm{d}\tau.

Then

J=Φ+tft0211L(t(τ),x(τ),u(τ))dτ.\boxed{ J = \Phi + \frac{t_f-t_0}{2} \int_{-1}^{1} L \left( t(\tau),\boldsymbol{x}(\tau),\boldsymbol{u}(\tau) \right) \,\mathrm{d}\tau. }

Free Initial and Final Times

If t0t_0 or tft_f is free, they become NLP decision variables.

The normalized computational domain remains fixed:

τ[1,1].\tau\in[-1,1].

However, the duration

tft0t_f-t_0

appears explicitly in:

Why Normalize Time

Time normalization provides:

Normalized Euler Defects

Let

1=τ0<τ1<<τK=1.-1=\tau_0<\tau_1<\cdots<\tau_K=1.

Define

Δτk=τk+1τk.\Delta\tau_k = \tau_{k+1}-\tau_k.

Euler forward in normalized time gives

xk+1=xk+Δτktft02f(tk,xk,uk).\boldsymbol{x}_{k+1} = \boldsymbol{x}_k + \Delta\tau_k \frac{t_f-t_0}{2} \boldsymbol{f}(t_k,\boldsymbol{x}_k,\boldsymbol{u}_k).

Thus,

xk+1xkΔτktft02f(tk,xk,uk)=0.\boxed{ \boldsymbol{x}_{k+1} - \boldsymbol{x}_k - \Delta\tau_k \frac{t_f-t_0}{2} \boldsymbol{f}(t_k,\boldsymbol{x}_k,\boldsymbol{u}_k) = \boldsymbol{0}. }

Normalized Quadrature

A left-rectangle approximation becomes

Ja=Φ+tft02k=0K1ΔτkL(tk,xk,uk).J_a = \Phi + \frac{t_f-t_0}{2} \sum_{k=0}^{K-1} \Delta\tau_k L(t_k,\boldsymbol{x}_k,\boldsymbol{u}_k).

For a uniform normalized mesh,

Δτ=2K.\Delta\tau = \frac{2}{K}.

Sparsity with Free Final Time

When tft_f is a decision variable, every defect depends on tft_f through the factor

tft02.\frac{t_f-t_0}{2}.

This introduces one additional dense column in the Jacobian.

However, the rest of the Jacobian remains sparse.

Thus, free-time problems retain strong sparse structure.

Finite Versus Infinite Horizons

The affine map above applies to finite intervals.

An infinite horizon,

t[t0,),t\in[t_0,\infty),

requires a nonlinear transformation, for example:

t=t0+1+τ1τ,τ[1,1).t = t_0 + \frac{1+\tau}{1-\tau}, \qquad \tau\in[-1,1).

Such mappings require special treatment because:

Solver-Oriented Implementation Workflow

  1. Normalize time.

  2. Select the mesh.

  3. Define the decision vector.

  4. Define the discretized objective.

  5. Define defect constraints.

  6. Define endpoint and path constraints.

  7. Provide sparse Jacobian information.

  8. Provide variable and constraint bounds.

  9. Solve the NLP.

  10. Verify convergence under mesh refinement.

Derivative Information

NLP solvers may use:

For large collocation problems, exact or automatic sparse derivatives are usually preferable.

Common Errors

  1. Treating the Jacobian as dense.

  2. Counting 2K12K-1 variables instead of 2K+12K+1 in the scalar Euler example.

  3. Forgetting endpoint-constraint nonzeros.

  4. Assuming sparsity disappears for nonlinear dynamics.

  5. Omitting the factor (tft0)/2(t_f-t_0)/2 after time normalization.

  6. Transforming the dynamics but not the cost.

  7. Forgetting that t(τ)t(\tau) depends on both endpoint times.

  8. Using a finite-interval affine map for an infinite-horizon problem.

  9. Supplying inconsistent derivative sparsity to the solver.

  10. Failing to verify mesh convergence.

Summary

  1. Collocation constraints depend locally on neighboring variables.

  2. This produces sparse, banded Jacobians.

  3. The scalar Euler example has 3K+23K+2 Jacobian nonzeros.

  4. Jacobian density approaches zero as the mesh is refined.

  5. Sparse NLP solvers exploit this structure.

  6. Time normalization maps arbitrary finite intervals to [1,1][-1,1].

  7. The dynamics scale by (tft0)/2(t_f-t_0)/2.

  8. The cost scales by the same factor.

  9. Free endpoint times become NLP decision variables.

  10. Normalization is foundational for advanced collocation and pseudospectral methods.