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.

Direct Collocation with Euler Discretization

The purpose of this section is to move from an abstract description of direct methods to a concrete nonlinear programming formulation. The focus is not on software syntax, but on the mathematical structure that must be created before an NLP solver can be used.

The main topics are:

Euler Forward: Time-Marching and Collocation Forms

For the ordinary differential equation

x˙(t)=f(t,x(t)),\dot{\boldsymbol{x}}(t)=\boldsymbol{f}(t,\boldsymbol{x}(t)),

Euler forward gives

xk+1=xk+hkf(tk,xk).\boldsymbol{x}_{k+1} = \boldsymbol{x}_k + h_k\boldsymbol{f}(t_k,\boldsymbol{x}_k).

This is the time-marching form.

The same equation can be written as a residual:

xk+1xkhkf(tk,xk)=0.\boxed{ \boldsymbol{x}_{k+1} - \boldsymbol{x}_k - h_k\boldsymbol{f}(t_k,\boldsymbol{x}_k) = \boldsymbol{0}. }

This is the collocation or defect form.

Mesh and Discrete State Vector

Let

t0<t1<<tK=tf,t_0<t_1<\cdots<t_K=t_f,

with

hk=tk+1tk.h_k=t_{k+1}-t_k.

Define

xkx(tk).\boldsymbol{x}_k\approx\boldsymbol{x}(t_k).

Collect all state approximations into

y=[x0x1xK].\boldsymbol{y} = \begin{bmatrix} \boldsymbol{x}_0\\ \boldsymbol{x}_1\\ \vdots\\ \boldsymbol{x}_K \end{bmatrix}.

The Euler residuals form a nonlinear system:

G(y)=0.\boldsymbol{G}(\boldsymbol{y})=\boldsymbol{0}.

Initial Conditions as Algebraic Constraints

Suppose

x(t0)=a,\boldsymbol{x}(t_0)=\boldsymbol{a},

where a\boldsymbol{a} is known.

One may either substitute

x0=a\boldsymbol{x}_0=\boldsymbol{a}

directly or add the residual equation

x0a=0.\boxed{ \boldsymbol{x}_0-\boldsymbol{a}=\boldsymbol{0}. }

The second form is common in collocation because it keeps all conditions in one residual system.

Newton’s Method for the Global Residual System

To solve

G(y)=0,\boldsymbol{G}(\boldsymbol{y})=\boldsymbol{0},

consider

G(y+Δy)G(y)+GyΔy.\boldsymbol{G}(\boldsymbol{y}+\Delta\boldsymbol{y})\approx \boldsymbol{G}(\boldsymbol{y}) + \frac{\partial\boldsymbol{G}}{\partial\boldsymbol{y}}\Delta\boldsymbol{y}.

Setting this approximation equal to zero gives

GyΔy=G(y).\frac{\partial\boldsymbol{G}}{\partial\boldsymbol{y}}\Delta\boldsymbol{y} = -\boldsymbol{G}(\boldsymbol{y}).

Hence,

Δy=(Gy)1G(y).\Delta\boldsymbol{y} = - \left( \frac{\partial\boldsymbol{G}}{\partial\boldsymbol{y}} \right)^{-1} \boldsymbol{G}(\boldsymbol{y}).

The Newton iteration is

y(j+1)=y(j)[Gy(y(j))]1G(y(j)).\boxed{ \boldsymbol{y}^{(j+1)} = \boldsymbol{y}^{(j)} - \left[ \frac{\partial\boldsymbol{G}}{\partial\boldsymbol{y}} \left(\boldsymbol{y}^{(j)}\right) \right]^{-1} \boldsymbol{G}\left(\boldsymbol{y}^{(j)}\right). }

In implementation, one solves the linear system rather than explicitly forming the inverse.

A Nonlinear Optimal-Control Example

Consider

minx(),u()J=120tf(x2(t)+u2(t))dt\boxed{ \min_{x(\cdot),u(\cdot)} J = \frac12 \int_0^{t_f} \left( x^2(t)+u^2(t) \right)\,\mathrm{d} t }

subject to

x˙(t)=x3(t)+u(t),\dot{x}(t) = -x^3(t)+u(t),

with

x(0)=a,x(tf)=b,x(0)=a, \qquad x(t_f)=b,

and fixed tft_f.

This problem is nonlinear because of the term x3-x^3.

Uniform Time Mesh

Choose KK intervals:

h=tft0K.h = \frac{t_f-t_0}{K}.

The mesh points are

tk=t0+kh,k=0,,K.t_k=t_0+kh, \qquad k=0,\ldots,K.

There are:

State and Control Discretization

For Euler forward, the state is defined at all mesh points:

x0,x1,,xK.x_0,x_1,\ldots,x_K.

The control is required only at the beginning of each interval:

u0,u1,,uK1.u_0,u_1,\ldots,u_{K-1}.

There is no uKu_K in this transcription because the final node does not begin another interval.

Discrete Dynamics

Euler forward gives

xk+1=xk+h(xk3+uk).x_{k+1} = x_k + h\left(-x_k^3+u_k\right).

The defect equation is

Δk=xk+1xkh(xk3+uk)=0,\boxed{ \Delta_k = x_{k+1} - x_k - h\left(-x_k^3+u_k\right) = 0, }

for

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

Equivalently,

Δk=xk+1xk+hxk3huk=0.\Delta_k = x_{k+1} - x_k + hx_k^3 - hu_k = 0.

Discretization of the Cost

The running cost is

L(x,u)=12(x2+u2).L(x,u)=\frac12(x^2+u^2).

Using a left-rectangle rule consistent with Euler forward,

0tf(x2+u2)dthk=0K1(xk2+uk2).\int_0^{t_f}(x^2+u^2)\,\mathrm{d} t \approx h\sum_{k=0}^{K-1}(x_k^2+u_k^2).

Therefore,

Ja=h2k=0K1(xk2+uk2).\boxed{ J_a = \frac{h}{2} \sum_{k=0}^{K-1} \left( x_k^2+u_k^2 \right). }

The original functional has become an ordinary function of finitely many variables.

Boundary Conditions

The continuous boundary conditions map to

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

These are equality constraints in the NLP.

Decision Vector

Define the decision vector

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

The total number of variables is

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

Complete NLP Formulation

The Euler direct-collocation problem is

minzh2k=0K1(xk2+uk2)subject toxk+1xkh(xk3+uk)=0,k=0,,K1,x0a=0,xKb=0.\boxed{ \begin{aligned} \min_{\boldsymbol{z}}\quad & \frac{h}{2} \sum_{k=0}^{K-1} \left( x_k^2+u_k^2 \right) \\[1mm] \text{subject to}\quad & x_{k+1}-x_k-h(-x_k^3+u_k)=0, \\ & k=0,\ldots,K-1, \\ & x_0-a=0, \\ & x_K-b=0. \end{aligned} }

This is a nonlinear programming problem.

Variables, Constraints, and Degrees of Freedom

The number of variables is

nz=2K+1.n_z=2K+1.

The number of equality constraints is

nc=K+2.n_c=K+2.

Therefore,

ndof=nznc=K1.\boxed{ n_{\mathrm{dof}} = n_z-n_c = K-1. }

The problem must have degrees of freedom because the optimizer must choose among many feasible trajectories.

Why the System Is Underdetermined Before Optimization

The defect equations and boundary conditions alone do not uniquely determine all state and control values.

There are many controls that may approximately transfer the state from aa to bb.

The objective selects the one that minimizes

120tf(x2+u2)dt.\frac12\int_0^{t_f}(x^2+u^2)\,\mathrm{d} t.

Thus:

Generalization to Multiple States and Controls

For

x˙=f(t,x,u),\dot{\boldsymbol{x}} = \boldsymbol{f}(t,\boldsymbol{x},\boldsymbol{u}),

with

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

Euler forward gives

xk+1xkhkf(tk,xk,uk)=0.\boldsymbol{x}_{k+1} - \boldsymbol{x}_k - h_k\boldsymbol{f}(t_k,\boldsymbol{x}_k,\boldsymbol{u}_k) = \boldsymbol{0}.

The number of variables becomes

(K+1)nx+Knu.(K+1)n_x+Kn_u.

The number of dynamic constraints becomes

Knx.Kn_x.

Endpoint and path constraints are added separately.

Forward Versus Backward Euler Indexing

Euler forward uses

f(tk,xk,uk).\boldsymbol{f}(t_k,\boldsymbol{x}_k,\boldsymbol{u}_k).

Backward Euler uses

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

Hence:

The quadrature indexing should be consistent with the dynamic discretization.

Accuracy of the Transcription

Euler forward is first-order accurate.

Therefore, the discrete optimal-control solution is expected to converge at first order under appropriate regularity and stability assumptions.

A valid numerical study should compare solutions for:

K,2K,4K,K,\quad 2K,\quad 4K,\ldots

and monitor:

Implementation Workflow

  1. Select KK.

  2. Compute hh.

  3. Create an initial guess for all states and controls.

  4. Build the objective function.

  5. Build the Euler defect constraints.

  6. Add endpoint constraints.

  7. Supply bounds if needed.

  8. Call an NLP solver.

  9. Reconstruct the trajectories.

  10. Refine the mesh and repeat.

Common Errors

  1. Using KK state points instead of K+1K+1.

  2. Including uKu_K in an Euler-forward transcription without a reason.

  3. Summing the quadrature from 0 to KK instead of 0 to K1K-1.

  4. Forgetting the endpoint constraints.

  5. Counting variables or constraints incorrectly.

  6. Solving the defect equations without including the objective.

  7. Calling the discrete solution exact.

  8. Failing to refine the mesh.

Summary

  1. Euler forward can be written as collocation defects.

  2. The state and control values become NLP decision variables.

  3. The running cost becomes a finite quadrature sum.

  4. Endpoint conditions become algebraic constraints.

  5. The resulting finite-dimensional problem is an NLP.

  6. The example contains 2K+12K+1 variables and K+2K+2 equality constraints.

  7. The remaining K1K-1 degrees of freedom are optimized through the cost.

  8. Mesh refinement is required to assess accuracy.

Connection. Once collocation has produced an NLP, its usefulness depends on exploiting local dependence, sparse derivatives, and a fixed normalized time interval.