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.

Continuous-Time Transcription and Collocation

The preceding chapters formulated and optimized trajectories through discrete transition maps. Physical models are often given instead by ordinary differential equations, so their states and controls are functions of time. A finite-dimensional optimizer cannot choose an entire function directly. Continuous-time trajectory optimization therefore begins by replacing those functions and their differential equations with finitely many variables and constraints on those variables.

How can that replacement preserve enough of the differential equation to make the resulting trajectory meaningful between the stored time points?

This replacement is called transcription, and the resulting finite optimization problem is a nonlinear program (NLP).

Direct collocation performs this replacement by storing state and control values at selected times and interpolating between them with low-degree polynomials. The differential equation is enforced at selected points on each time interval. This chapter develops that construction from one simple example through Euler, trapezoidal, and Hermite--Simpson transcriptions, then applies it to the motion of an overhead crane.

A One-Interval Example

How can a constraint on four endpoint values ensure that the chosen control produces the required displacement?

Consider a point that must move from x(0)=0x(0)=0 to x(1)=1x(1)=1. Its velocity is the control, so

x˙(t)=u(t),\dot x(t)=u(t),

and the objective penalizes squared control effort,

minimize⁡x(⋅),u(⋅)∫01u(t)2 dt.\underset{x(\cdot),u(\cdot)}{\operatorname{minimize}} \quad \int_0^1 u(t)^2\,dt.

Both xx and uu are unknown functions. As a first finite approximation, retain only their endpoint values x0,x1,u0,u1x_0,x_1,u_0,u_1 and let the control vary linearly between u0u_0 and u1u_1. Integrating x˙=u\dot x=u means that the change in state equals the area under this control. The shaded region below is a unit-width trapezoid. Its area is the average of its two endpoint heights, u0u_0 and u1u_1, multiplied by the width.

Figure 1:Drag the endpoint controls or play the accumulation from left to right. The shaded rectangle and triangle sum to the state change implied by x˙=u\dot x=u. Setting the interval width to h=1h=1 gives the state-change relation x1−x0=(u0+u1)/2x_1-x_0=(u_0+u_1)/2.

Loading...
A linear control between two endpoint values forms a trapezoid whose rectangle and triangle areas sum to the state change.

Figure 2:A linear control connects u0u_0 and u1u_1 across an interval of width hh. The rectangle hu0hu_0 and triangle h(u1−u0)/2h(u_1-u_0)/2 sum to h(u0+u1)/2h(u_0+u_1)/2. Because x˙=u\dot x=u, this area equals x1−x0x_1-x_0.

The optimizer must choose endpoint states and controls that agree with this area calculation. Otherwise, it could choose x0=0x_0=0 and x1=1x_1=1 while setting both controls to zero: the endpoint conditions would hold, but zero velocity could not produce the displacement. To exclude such choices, the stored state change x1−x0x_1-x_0 must equal the change (u0+u1)/2(u_0+u_1)/2 predicted by integrating the control. Moving both quantities to the left gives the constraint

x1−x0−12(u0+u1)=0.x_1-x_0-\frac{1}{2}(u_0+u_1)=0.

The left-hand side measures the mismatch between these two changes and is called the defect. Requiring that mismatch to vanish gives a defect constraint, which enforces the dynamics within the chosen approximation. The equation is algebraic because it relates the four numbers x0,x1,u0,u1x_0,x_1,u_0,u_1 through arithmetic operations; there is no unknown function to differentiate or integrate when evaluating it. An optimizer can therefore check the constraint directly for each candidate set of endpoint values.

Approximating the running-cost integral by the average of its endpoint values gives the finite nonlinear program

minimize⁡x0,x1,u0,u112(u02+u12)subject tox0=0,x1=1,x1−x0−12(u0+u1)=0.\begin{aligned} \underset{x_0,x_1,u_0,u_1}{\operatorname{minimize}} \quad&\frac{1}{2}(u_0^2+u_1^2)\\ \text{subject to}\quad&x_0=0,\qquad x_1=1,\\ &x_1-x_0-\frac{1}{2}(u_0+u_1)=0. \end{aligned}

The boundary conditions reduce the defect to u0+u1=2u_0+u_1=2. Substituting u1=2−u0u_1=2-u_0 into the objective gives

12(u02+(2−u0)2)=(u0−1)2+1.\frac12\left(u_0^2+(2-u_0)^2\right) =(u_0-1)^2+1.

The squared term is minimized at u0=1u_0=1, which also gives u1=1u_1=1. The resulting interpolation is the exact solution u(t)=1u(t)=1 and x(t)=tx(t)=t.

This example already contains the main ingredients of direct collocation. The function values became optimization variables, integration became a weighted sum, and the differential equation became an equality constraint. The remaining sections construct these operations systematically for nonlinear vector dynamics and higher-degree polynomials.

From a Continuous Problem to a Finite NLP

How do nodal state and control values, quadrature weights, and defect equations assemble into one nonlinear program?

We retain the earlier notation x∈Rn\mathbf x\in\mathbb R^n for the state, u∈Rm\mathbf u\in\mathbb R^m for the control, and cc for cost. Here tt is continuous physical time, while kk will index mesh intervals. The running cost c(x,u,t)c(\mathbf x,\mathbf u,t) is a cost per unit time; integrating it over an interval produces the counterpart of the discrete stage cost ckc_k. The terminal cost is written cfc_f because the final physical time is tft_f. Scalar examples omit boldface.

With inequalities g≤0\mathbf g\leq\mathbf0 and equalities h=0\mathbf h=\mathbf0, the continuous-time Bolza problem is

minimize⁡x(⋅),u(⋅),tfcf(x(tf),tf)+∫t0tfc(x(t),u(t),t) dtsubject tox˙(t)=f(x(t),u(t),t),h(x(t0),x(tf),tf)=0,g(x(t),u(t),t)≤0.\begin{aligned} \underset{\mathbf{x}(\cdot),\mathbf{u}(\cdot),t_f}{\operatorname{minimize}} \quad& c_f(\mathbf{x}(t_f),t_f) +\int_{t_0}^{t_f} c(\mathbf{x}(t),\mathbf{u}(t),t)\,dt\\ \text{subject to}\quad& \dot{\mathbf{x}}(t)=\mathbf{f}(\mathbf{x}(t),\mathbf{u}(t),t),\\ &\mathbf{h}(\mathbf{x}(t_0),\mathbf{x}(t_f),t_f)=\mathbf0,\\ &\mathbf{g}(\mathbf{x}(t),\mathbf{u}(t),t)\leq\mathbf0. \end{aligned}

Here x(t)∈Rn\mathbf{x}(t)\in\mathbb R^{n} is the state, u(t)∈Rm\mathbf{u}(t)\in\mathbb R^{m} is the control, cfc_f is a terminal cost, and cc is a running cost. The equality h=0\mathbf{h}=\mathbf0 imposes endpoint conditions, while g≤0\mathbf{g}\leq\mathbf0 represents constraints that must hold along the path. Setting c=0c=0 gives the Mayer special case, while setting cf=0c_f=0 gives the Lagrange special case. All three forms use the same transcription machinery.

Two transcription strategies differ in which values become decision variables and in how they impose the differential equation:

StrategyFinite decision variablesTreatment of the ODE
ShootingControl parameters and, in multiple shooting, selected boundary statesA time integrator advances the state sequentially inside each shooting interval
Direct collocationState and control values at selected nodesAlgebraic defect equations enforce the ODE simultaneously

Shooting and collocation are therefore distinct transcription strategies. A collocation method may reproduce a familiar integration formula, but it exposes the state values to the NLP rather than hiding every state update inside a simulation. The term direct indicates that the continuous problem is converted directly into an optimization problem, without first deriving necessary conditions such as the Pontryagin equations.

Let

t0<t1<⋯<tN=tf,hk=tk+1−tk,t_0<t_1<\cdots<t_N=t_f,\qquad h_k=t_{k+1}-t_k,

be a mesh with k=0,…,N−1k=0,\ldots,N-1. We write xk\mathbf x_k and uk\mathbf u_k for values at mesh time tkt_k, as in the earlier discrete-time chapters; the subscript is an index, not a physical time. On each interval, the normalized coordinate is τ=(t−tk)/hk\tau=(t-t_k)/h_k, or equivalently

t=tk+hkτ,0≤τ≤1.t=t_k+h_k\tau,\qquad 0\leq\tau\leq1.

Every physical interval is thereby mapped to the same reference interval [0,1][0,1]. Differentiation and integration formulas can be constructed once on this reference interval; the length hkh_k then supplies the physical-time scaling. If the final time is also optimized, the interval lengths become variables or fixed fractions of the variable horizon; the reference-interval operators remain unchanged.

One Polynomial, Two Coordinate Systems

Should a polynomial trajectory be stored by its coefficients or by its values at support nodes, and how are the two descriptions related?

The opening example represented a line by its two endpoint values. Higher-order collocation uses the same idea with more values. The polynomials of degree at most rr form the space

Pr={p:deg⁡p≤r}\mathcal P_r=\{p:\deg p\leq r\}

This space, denoted by Pr\mathcal P_r, has dimension r+1r+1. Choosing a basis {ϕ0,…,ϕr}\{\phi_0,\ldots,\phi_r\} gives coefficient coordinates

p(τ)=∑j=0rajϕj(τ).p(\tau)=\sum_{j=0}^{r}a_j\phi_j(\tau).

The monomial choice ϕj(τ)=τj\phi_j(\tau)=\tau^j is familiar, but it is only a coordinate system. The polynomial is the function pp, not its particular list of coefficients.

The same polynomial can instead be identified by its values. Choose r+1r+1 distinct points

σ0,…,σr∈[0,1],\sigma_0,\ldots,\sigma_r\in[0,1],

and record

yi=p(σi).y_i=p(\sigma_i).

These points are called support nodes: once the degree is restricted to at most rr, the r+1r+1 stored values determine the whole polynomial. Storing values is useful for trajectory optimization because a bound on the state at a node then becomes a bound on a decision variable. To evaluate the dynamics between nodes, however, we need a formula that reconstructs the polynomial from those values.

For degree one, take the support nodes 0 and 1. A line has the form p(τ)=a+bτp(\tau)=a+b\tau. The first endpoint condition gives a=y0a=y_0, and the second gives a+b=y1a+b=y_1, so b=y1−y0b=y_1-y_0. Substitution and regrouping give

p(τ)=y0(1−τ)+y1τ.p(\tau)=y_0(1-\tau)+y_1\tau.

The weights 1−τ1-\tau and τ\tau enforce the two endpoint conditions: at 0, the formula returns y0y_0, and at 1, it returns y1y_1. Between the endpoints, the weights vary continuously; at τ=1/4\tau=1/4, for example, the value is 3y0/4+y1/43y_0/4+y_1/4. This is the unique line through the two prescribed values. Without the degree restriction, other curves could pass through them. Even for this same line, y0+(y1−y0)τy_0+(y_1-y_0)\tau is an equivalent representation. The weighted form is convenient because each stored value has its own function that determines its contribution throughout the interval.

With more nodes, the same construction needs one weight function ℓj\ell_j per stored value yjy_j. To recover yjy_j at its own node without altering the values at the other nodes, ℓj\ell_j must equal one at σj\sigma_j and zero at every other support node. A polynomial with those zeros contains the factors (τ−σm)(\tau-\sigma_m) for all m≠jm\ne j. Dividing their product by its value at σj\sigma_j makes the value there equal to one. This constructs the Lagrange cardinal function

ℓj(τ)=∏m=0m≠jrτ−σmσj−σm.\ell_j(\tau) =\prod_{\substack{m=0\\m\neq j}}^r \frac{\tau-\sigma_m}{\sigma_j-\sigma_m}.

At a support node σi\sigma_i, one factor in the numerator is zero unless i=ji=j. When i=ji=j, every numerator equals its corresponding denominator. Consequently,

ℓj(σi)=δij,\ell_j(\sigma_i)=\delta_{ij},

where the Kronecker delta δij\delta_{ij} is shorthand for one when i=ji=j and zero otherwise. This identity specifies the values at the nodes only. At any other τ\tau, the product formula gives a smoothly varying polynomial weight, which can be negative or exceed one for higher degrees. Thus, unlike a line between two endpoint values, a higher-degree interpolant can take values outside the range of its stored values. The cardinal functions reconstruct the polynomial throughout the interval by

p(τ)=∑j=0ryjℓj(τ),yj=p(σj).\boxed{ p(\tau)=\sum_{j=0}^{r}y_j\ell_j(\tau), \qquad y_j=p(\sigma_j). }

At a node σi\sigma_i, all terms except yiℓi(σi)=yiy_i\ell_i(\sigma_i)=y_i vanish. Between nodes, the weighted sum supplies the intervening values. Changing one stored value yjy_j by Δyj\Delta y_j changes the curve by Δyjℓj(τ)\Delta y_j\ell_j(\tau), so the same function describes how that variable affects the entire polynomial.

The uniqueness of this reconstruction follows from a basic root-counting argument. If two polynomials in Pr\mathcal P_r have the same r+1r+1 nodal values, their difference has r+1r+1 distinct roots. A nonzero polynomial of degree at most rr cannot have that many roots, so the two polynomials must be identical.

For a scalar polynomial, collect the coefficients and values into column vectors a=(a0,…,ar)⊤\mathbf a=(a_0,\ldots,a_r)^\top and y=(y0,…,yr)⊤\mathbf y=(y_0,\ldots,y_r)^\top. The coefficient and nodal descriptions are related by the evaluation matrix

Vij=ϕj(σi),y=Va.V_{ij}=\phi_j(\sigma_i), \qquad \mathbf{y}=V\mathbf{a}.

Distinct support nodes make VV invertible by the same root-counting argument. Thus a\mathbf{a} and y\mathbf{y} are two coordinate vectors for one polynomial, rather than two different approximations.

For example, take p(τ)=1+2τ−τ2p(\tau)=1+2\tau-\tau^2 and the nodes 0,12,10,\tfrac12,1. In monomial coordinates,

a=[12−1],V=[10011214111],\mathbf{a}= \begin{bmatrix}1\\2\\-1\end{bmatrix}, \qquad V= \begin{bmatrix} 1&0&0\\ 1&\tfrac12&\tfrac14\\ 1&1&1 \end{bmatrix},

whereas the nodal coordinates are

y=Va=[1742].\mathbf{y}=V\mathbf{a}= \begin{bmatrix}1\\\tfrac74\\2\end{bmatrix}.

Both vectors describe exactly the same quadratic. Direct collocation uses coordinates like y\mathbf{y}: state values and control values at meaningful points. It does not ask the NLP solver to choose monomial coefficients. Software may use coefficient calculations when it constructs fixed operators, but those calculations remain outside the NLP.

Figure 3:One quadratic, two coordinate systems. Evaluating the monomial coefficients a\mathbf{a} at the support nodes gives y=Va\mathbf{y}=V\mathbf{a}. Direct collocation stores the nodal vector y\mathbf{y}; the fixed operators DD and ww then return its nodal derivatives and exact integral without adding optimization variables.

Matplotlib is building the font cache; this may take a moment.
<Figure size 740x370 with 2 Axes>

Polynomial space, basis, and nodes are different choices

The construction separates three decisions that are easy to conflate:

Changing the basis does not change the exact polynomial space, although it can change numerical conditioning. Changing the nodes changes the interpolation and the operators built from it. The higher-order node families introduced later can still use Lagrange nodal coordinates in the NLP; choosing those nodes does not require optimizing orthogonal-polynomial coefficients.

Polynomial Interpolation and Least-Squares Regression

When nodal values do not determine an exact interpolant, which projection recovers a polynomial that best matches the available samples?

Interpolation and polynomial regression impose different requirements on the same data. Six values at six distinct nodes determine one polynomial of degree at most five that passes through every point. If the values are noisy observations and the aim is to estimate a quadratic trend, a quadratic will generally be unable to pass through all six. Least-squares regression then chooses its three coefficients to minimize the sum of squared discrepancies. The figure below applies both choices to the same six points. Write AA for the matrix obtained by evaluating the chosen polynomial basis at the supplied input points. The two algebraic problems are then compared below.

Polynomial interpolationLeast-squares regression
InputExact value conditionsUsually noisy or overdetermined observations
Algebraic problemSatisfy Aa=yA\mathbf{a}=\mathbf{y} exactlyMinimize ∥Aa−y∥22\lVert A\mathbf{a}-\mathbf{y}\rVert_2^2
ResidualZero when the value conditions uniquely determine a polynomialGenerally nonzero
Typical purposeRepresent a function from exact nodal dataEstimate a trend or conditional mean

If AA is square and invertible, least squares happens to return the exact interpolant with zero residual. That special overlap does not erase the conceptual distinction.

Figure 4:Two polynomials fitted to the same six points (black dots). The solid blue degree-five interpolant passes through every point. The dashed orange quadratic regression minimizes the sum of squared residuals, shown as gray vertical segments. The polynomial degrees differ because a quadratic generally cannot satisfy all six value conditions exactly.

<Figure size 550x280 with 1 Axes>

In direct collocation, the nodal states are unknown decision variables rather than observations. Each candidate vector of nodal values defines one interpolating polynomial exactly. The optimizer selects a candidate whose ODE residual vanishes at the collocation nodes. A numerical solver may temporarily work with a scalar measure of constraint violation, but the collocation conditions remain equality constraints rather than a statistical regression loss.

Fixed Operators from Nodal Values

How can the stored values give us both the slopes and the integral of every candidate polynomial?

The nodal representation also turns differentiation and integration into matrix and vector products. Once the nodes are chosen, the required arrays can be computed once and reused for every candidate trajectory. The optimizer can then evaluate slopes and integrals as it changes the nodal values, without repeating symbolic differentiation or numerical integration. These operations are exact for the represented polynomial.

This is possible because the cardinal functions stay fixed while only their coefficients yjy_j change. In the representation

p(τ)=∑j=0ryjℓj(τ),p(\tau)=\sum_{j=0}^r y_j\ell_j(\tau),

each yjy_j is constant with respect to τ\tau, so differentiation acts only on ℓj\ell_j. To obtain the slopes needed by the ODE, differentiate and then evaluate at a node σi\sigma_i:

p′(σi)=∑j=0rℓj′(σi)⏟Dijyj,p'(\sigma_i)=\sum_{j=0}^r \underbrace{\ell_j'(\sigma_i)}_{D_{ij}}y_j,

while integration over the reference interval gives

∫01p(τ) dτ=∑j=0r(∫01ℓj(τ) dτ)⏟wjyj.\int_0^1p(\tau)\,d\tau =\sum_{j=0}^r \underbrace{\left(\int_0^1\ell_j(\tau)\,d\tau\right)}_{w_j}y_j.

The resulting differentiation matrix DD and integration weights ww depend only on the chosen nodes. Their entries record the derivatives and areas of the fixed cardinal functions. Multiplication by the current nodal values combines these contributions into the derivative or integral of the current polynomial. This is how the transcription supplies the calculus needed by the dynamics and cost through arithmetic on the decision variables.

For a concrete construction, suppose a quadratic is stored by its values y0,ym,y1y_0,y_m,y_1 at 0,12,10,\tfrac12,1, where mm denotes the midpoint. The desired outputs are its slope at each of these nodes and its integral over [0,1][0,1]. To build the arrays that return those outputs for any choice of the three values, first construct the three cardinal functions multiplying them:

ℓ0(τ)=(τ−12)(τ−1)(0−12)(0−1)=2τ2−3τ+1,ℓm(τ)=τ(τ−1)(12−0)(12−1)=4τ(1−τ),ℓ1(τ)=τ(τ−12)(1−0)(1−12)=2τ2−τ.\begin{aligned} \ell_0(\tau) &=\frac{(\tau-\frac12)(\tau-1)}{(0-\frac12)(0-1)} =2\tau^2-3\tau+1,\\ \ell_m(\tau) &=\frac{\tau(\tau-1)}{(\frac12-0)(\frac12-1)} =4\tau(1-\tau),\\ \ell_1(\tau) &=\frac{\tau(\tau-\frac12)}{(1-0)(1-\frac12)} =2\tau^2-\tau. \end{aligned}

These are the three contributions in p(τ)=y0ℓ0(τ)+ymℓm(τ)+y1ℓ1(τ)p(\tau)=y_0\ell_0(\tau)+y_m\ell_m(\tau)+y_1\ell_1(\tau). Their derivatives are 4τ−34\tau-3, 4−8τ4-8\tau, and 4τ−14\tau-1. At the left endpoint they give the weights −3,4,−1-3,4,-1, so p′(0)=−3y0+4ym−y1p'(0)=-3y_0+4y_m-y_1. Evaluation at the midpoint and right endpoint supplies the other two rows of the differentiation matrix:

[p′(0)p′(12)p′(1)]=[−34−1−1011−43]⏟D[y0ymy1].\begin{bmatrix} p'(0)\\ p'(\tfrac12)\\ p'(1) \end{bmatrix} = \underbrace{ \begin{bmatrix} -3&4&-1\\ -1&0&1\\ 1&-4&3 \end{bmatrix}}_{D} \begin{bmatrix} y_0\\y_m\\y_1 \end{bmatrix}.

Thus a matrix-vector product turns the three stored values into the three nodal derivatives. Integrating the same cardinal functions gives

∫01p(τ) dτ=[164616]⏟wT[y0ymy1].\int_0^1 p(\tau)\,d\tau = \underbrace{ \begin{bmatrix} \tfrac16&\tfrac46&\tfrac16 \end{bmatrix}}_{w^\mathsf T} \begin{bmatrix} y_0\\y_m\\y_1 \end{bmatrix}.

The row wTw^\mathsf T turns the same three values into the exact integral of their quadratic interpolant. The matrix DD differentiates every polynomial in P2\mathcal P_2 exactly, and ww integrates every polynomial in that space exactly. “Fixed operator” means that these arrays remain constant while the NLP changes the nodal values.

A transcription may use nodes for three distinct purposes:

Node roleWhat it does
Support nodeSupplies coordinates that define a polynomial
Collocation nodeSupplies a point where the ODE residual is constrained
Quadrature nodeSupplies a point used to approximate an integral

A method often reuses one set of points for two or three roles. That is a design choice, not a definition. For example, a state polynomial can be supported at one set of nodes and differentiated at different collocation nodes. The next section begins with slope values at collocation nodes and uses integration to recover state values.

From Nodal Slopes to Collocation Constraints

How do those fixed maps convert differential equations into algebraic constraints at the chosen collocation nodes?

A single polynomial can represent a trajectory over the entire horizon; the opening example’s solution x(t)=tx(t)=t already does so. Why introduce several pieces? Consider the same scalar dynamics x˙=u\dot x=u, starting from x(0)=0x(0)=0, but now moving right at unit speed until t=1/2t=1/2 and then left at unit speed:

u(t)={1,0≤t<12,−1,12<t≤1,x(t)={t,0≤t≤12,1−t,12≤t≤1.u(t)=\begin{cases} 1,&0\leq t<\tfrac12,\\ -1,&\tfrac12<t\leq1, \end{cases} \qquad x(t)=\begin{cases} t,&0\leq t\leq\tfrac12,\\ 1-t,&\tfrac12\leq t\leq1. \end{cases}

The state is continuous, but its slope changes abruptly at the switching time. Two line segments represent it exactly. A single polynomial has a continuous derivative, so it cannot reproduce this corner exactly, although it can approximate the trajectory. The ODE here holds on either side of the switch; the control’s value at that one instant does not affect its integral.

Even when the trajectory is smooth, some portions may change much faster than others. Separate polynomial pieces let us shorten the mesh intervals near a rapid change while retaining longer intervals elsewhere. Increasing the degree of one global polynomial adds flexibility across the whole horizon. The local representation also gives the optimizer useful structure: each interval’s dynamics constraints involve only its own stage values and neighboring endpoint states. A global polynomial couples values across the horizon through its differentiation matrix.

For a trajectory that is smooth throughout the horizon, a single polynomial of sufficiently high degree can be an efficient choice. Piecewise polynomials give us local control over resolution, allow changes in slope at joins, and keep the constraint derivatives sparse. They require us to connect adjacent pieces explicitly so that the state remains continuous.

We therefore represent the trajectory by a separate polynomial on each mesh interval [tk,tk+1][t_k,t_{k+1}]. The full approximation xh\mathbf{x}_h is piecewise polynomial. To construct the piece on interval kk, use its local coordinate τ=(t−tk)/hk\tau=(t-t_k)/h_k, where hk=tk+1−tkh_k=t_{k+1}-t_k, and write

pk(τ):=xh(tk+hkτ),0≤τ≤1.\mathbf{p}_k(\tau):=\mathbf{x}_h(t_k+h_k\tau),\qquad 0\le\tau\le1.

Thus pk(0)\mathbf{p}_k(0) is the state at the start of this interval and pk(1)\mathbf{p}_k(1) is the state at its end. On the next interval, the local coordinate starts again at zero, and a different polynomial pk+1\mathbf{p}_{k+1} describes the trajectory. The reference interval and its integration weights can be reused even when the physical intervals have different lengths.

Choose ss collocation nodes τ1,…,τs\tau_1,\ldots,\tau_s on [0,1][0,1]. On interval kk, node τj\tau_j corresponds to the physical time tk+hkτjt_k+h_k\tau_j. The state and control values there are xk,j\mathbf{x}_{k,j} and uk,j\mathbf{u}_{k,j}. This local evaluation point, together with its state and control values, is called a stage. At each stage, the differential equation prescribes the physical-time slope

fk,j=f(xk,j,uk,j,tk+hkτj)\mathbf{f}_{k,j} =\mathbf{f}(\mathbf{x}_{k,j},\mathbf{u}_{k,j},t_k+h_k\tau_j)

for j=1,…,sj=1,\ldots,s. Let ℓj\ell_j be the Lagrange cardinal function associated with the nodes τ1,…,τs\tau_1,\ldots,\tau_s. Interpolating these slopes gives the physical-time derivative on this one interval:

x˙h(tk+hkτ)=∑j=1sfk,jℓj(τ).\dot{\mathbf{x}}_h(t_k+h_k\tau) =\sum_{j=1}^{s}\mathbf{f}_{k,j}\ell_j(\tau).

This polynomial agrees with the ODE slope fk,j\mathbf{f}_{k,j} at every collocation node of interval kk. Integrating from its left endpoint, whose stored state is xk\mathbf{x}_k, constructs the entire state piece:

pk(τ)=xk+hk∑j=1s(∫0τℓj(η) dη)fk,j.\mathbf{p}_k(\tau) =\mathbf{x}_k+h_k\sum_{j=1}^{s} \left(\int_0^\tau\ell_j(\eta)\,d\eta\right)\mathbf{f}_{k,j}.

The factor hkh_k converts integration in normalized time into integration in physical time: dt=hk dτdt=h_k\,d\tau. For example, a constant physical slope f\mathbf{f} acting from τ=0\tau=0 to τ=τi\tau=\tau_i acts for hkτih_k\tau_i units of time and changes the state by hkτifh_k\tau_i\mathbf{f}. Without hkh_k, the formula would treat every physical interval as having unit duration. Equivalently, the chain rule gives pk′(τ)=hkx˙h(tk+hkτ)\mathbf{p}_k'(\tau)=h_k\dot{\mathbf{x}}_h(t_k+h_k\tau).

The stored stage state xk,i\mathbf{x}_{k,i} must lie on this polynomial at τi\tau_i. Imposing xk,i=pk(τi)\mathbf{x}_{k,i}=\mathbf{p}_k(\tau_i) gives the stage equations

xk,i=xk+hk∑j=1sAijfk,j,Aij=∫0τiℓj(τ) dτ.\mathbf{x}_{k,i} =\mathbf{x}_k+h_k\sum_{j=1}^{s}A_{ij}\mathbf{f}_{k,j}, \qquad A_{ij}=\int_0^{\tau_i}\ell_j(\tau)\,d\tau.

Each row of AA integrates only as far as one stage within interval kk. These are simultaneous constraints on the stage values: the slopes on the right depend on the state and control variables being chosen. To reach the end of the interval instead, set τ=1\tau=1 and require the resulting value pk(1)\mathbf{p}_k(1) to equal the stored right endpoint xk+1\mathbf{x}_{k+1}:

xk+1=xk+hk∑j=1sbjfk,j,bj=∫01ℓj(τ) dτ.\boxed{ \mathbf{x}_{k+1} =\mathbf{x}_k+h_k\sum_{j=1}^{s}b_j\mathbf{f}_{k,j}, \qquad b_j=\int_0^1\ell_j(\tau)\,d\tau. }

The coefficients bjb_j integrate the cardinal functions over the full reference interval. The endpoint equation is a defect constraint: it requires the stored endpoint to match the endpoint obtained by integrating the slopes of piece kk. The next piece starts from that same stored value, so the two pieces meet:

pk(1)=xk+1=pk+1(0).\mathbf{p}_k(1)=\mathbf{x}_{k+1}=\mathbf{p}_{k+1}(0).

This shared variable enforces state continuity across the join. If an implementation stores separate endpoint variables for the two pieces, it must impose an equality between them. Choosing an endpoint as a collocation node does not by itself join the pieces. Continuity of the state also does not require continuity of its derivative; neighboring pieces can meet with different slopes.

Three quadratic state segments meet at shared endpoint states in physical time. The middle segment is repeated on a normalized time axis from zero to one, with two interior stage values and their slopes marked.

Figure 5:A scalar trajectory consists of polynomial pieces joined at shared endpoint states (squares). The middle piece pkp_k is shown in blue in both panels; only its time coordinate changes. The stage values (orange dots) lie at τ1=1/3\tau_1=1/3 and τ2=2/3\tau_2=2/3. Tangent marks in the lower panel have slopes pk′(τj)=hkfk,jp_k'(\tau_j)=h_kf_{k,j} because that axis uses normalized time. The stage equations place the dots on the piece, and the endpoint defect makes it reach xk+1x_{k+1}, where the next piece begins. This schematic uses quadratic state pieces and linear slope interpolants.

The running-cost integral can be treated by exactly the same construction. As in the earlier Bolza-to-Mayer reduction, introduce a scalar state y(t)y(t) that records the cost accumulated since t0t_0:

y(t)=∫t0tc(x(s),u(s),s) ds,y˙(t)=c(x(t),u(t),t),y(t0)=0.y(t)=\int_{t_0}^{t}c(\mathbf{x}(s),\mathbf{u}(s),s)\,ds, \qquad \dot y(t)=c(\mathbf{x}(t),\mathbf{u}(t),t),\qquad y(t_0)=0.

The original objective is now cf(x(tf),tf)+y(tf)c_f(\mathbf{x}(t_f),t_f)+y(t_f). The augmented state (x⊤,y)⊤(\mathbf{x}^{\top},y)^{\top} has two rates of change: f\mathbf{f} supplies the physical state rate and cc supplies the cost rate. Applying the same collocation method to this augmented ODE evaluates both rates at each stage’s state, control, and time. In particular, the cost rate at stage jj of interval kk is

ck,j:=c(xk,j,uk,j,tk+hkτj).c_{k,j}:=c(\mathbf{x}_{k,j},\mathbf{u}_{k,j},t_k+h_k\tau_j).

Let yky_k and yk,iy_{k,i} denote the accumulated-cost values at the interval’s left endpoint and at stage ii. Integrating the cost-rate interpolant to a stage and to the right endpoint gives

yk,i=yk+hk∑j=1sAijck,j,yk+1=yk+hk∑j=1sbjck,j.y_{k,i}=y_k+h_k\sum_{j=1}^{s}A_{ij}c_{k,j}, \qquad y_{k+1}=y_k+h_k\sum_{j=1}^{s}b_jc_{k,j}.

These are the same stage and endpoint equations as for x\mathbf{x}, with ck,jc_{k,j} in place of fk,j\mathbf{f}_{k,j}. The increase in accumulated cost across interval kk therefore supplies its contribution to the discrete objective:

ck:=yk+1−yk=hk∑j=1sbjck,j≈∫tktk+1c(xh(t),uh(t),t) dt.c_k:=y_{k+1}-y_k =h_k\sum_{j=1}^{s}b_jc_{k,j} \approx\int_{t_k}^{t_{k+1}}c(\mathbf{x}_h(t),\mathbf{u}_h(t),t)\,dt.

Here uh\mathbf{u}_h is the piecewise control approximation. The single-index ckc_k is an interval cost, whereas ck,jc_{k,j} is a sampled cost rate; the factor hkh_k gives them different units. The weighted sum integrates the polynomial interpolating the sampled cost rates exactly. It approximates the running-cost integral because the composed function c(xh(t),uh(t),t)c(\mathbf{x}_h(t),\mathbf{u}_h(t),t) need not itself be that polynomial. Such a weighted-sum approximation is called a quadrature rule.

Since y0=0y_0=0, summing the interval increments gives yN=∑k=0N−1cky_N=\sum_{k=0}^{N-1}c_k. The accumulated-cost variables can therefore be eliminated and the sum used directly in the objective. Introducing yy explains why applying one collocation scheme to both rates uses the same nodes and weights; it does not require adding cost variables to the implementation. A different quadrature rule is also possible, with the state and control polynomials evaluated at that rule’s nodes.

Choosing a polynomial for the control

The state and control play different roles. The ODE constrains the state’s derivative, so integrating an interpolant of ss slopes gives a state polynomial of degree at most ss. There is no corresponding ODE for the control in this problem. Its representation is a separate choice: a constant command on each interval, a line between endpoint commands, or a higher-degree polynomial.

For example, with two endpoint slopes the state polynomial is quadratic. The control can still be the line

uh(tk+hkτ)=(1−τ)uk+τuk+1.\mathbf u_h(t_k+h_k\tau) =(1-\tau)\mathbf u_k+\tau\mathbf u_{k+1}.

These degrees need not match. Also, substituting polynomial state and control curves into a nonlinear f\mathbf f need not produce a polynomial. Collocation matches the state derivative to f\mathbf f at the chosen nodes, rather than requiring the ODE to hold identically between them.

To make the control choice explicit, select distinct control support nodes ρ0,…,ρdu∈[0,1]\rho_0,\ldots,\rho_{d_u}\in[0,1] and construct their cardinal functions ψ0,…,ψdu\psi_0,\ldots,\psi_{d_u}. The decision variables u^k,r\widehat{\mathbf u}_{k,r} are control values at these support nodes:

uh(tk+hkτ)=∑r=0duu^k,rψr(τ),uk,j=∑r=0duBjru^k,r,Bjr:=ψr(τj).\mathbf u_h(t_k+h_k\tau) =\sum_{r=0}^{d_u}\widehat{\mathbf u}_{k,r}\psi_r(\tau), \qquad \mathbf u_{k,j} =\sum_{r=0}^{d_u}B_{jr}\widehat{\mathbf u}_{k,r}, \quad B_{jr}:=\psi_r(\tau_j).

Thus the stage controls uk,j\mathbf u_{k,j} are computed from the control variables; they are independent variables only when the representation allows independent values at all those stages. For a constant control, du=0d_u=0 and every entry of BB is one. For a linear control supported at 0,10,1, row jj of BB is (1−τj,τj)(1-\tau_j,\tau_j).

Using more control support values than collocation stages leaves some control variations invisible to those stage samples. The examples below use du+1≤sd_u+1\leq s; a richer control representation needs additional sampling or other constraints to account for those variations.

The ODE requires continuous states, but it can admit controls that jump between intervals. Independent control polynomials therefore need no continuity constraint unless the model or chosen parameterization requires one. Sharing endpoint controls between neighboring linear pieces enforces continuity. With separate local variables, the equivalent equality is

∑r=0duψr(1)u^k,r=∑r=0duψr(0)u^k+1,r.\sum_{r=0}^{d_u}\psi_r(1)\widehat{\mathbf u}_{k,r} =\sum_{r=0}^{d_u}\psi_r(0)\widehat{\mathbf u}_{k+1,r}.

At a jump, endpoint stages use the control belonging to their own interval. Finally, bounds on support values guarantee bounds throughout a constant or linear control segment, because its values are convex combinations of its endpoints. A higher-degree polynomial can overshoot those values, so support bounds alone no longer give that guarantee.

After all intervals are assembled, collect the nodal states and controls into the decision vector

z=col⁡ ⁣({xk}k=0N,{xk,j}k=0, j=1N−1, s,{u^k,r}k=0, r=0N−1, du).\mathbf z=\operatorname{col}\!\left( \{\mathbf x_k\}_{k=0}^{N}, \{\mathbf x_{k,j}\}_{k=0,\,j=1}^{N-1,\,s}, \{\widehat{\mathbf u}_{k,r}\}_{k=0,\,r=0}^{N-1,\,d_u} \right).

Here col⁡\operatorname{col} stacks the listed vectors into one column, omitting duplicate variables when a stage shares a mesh endpoint. Stage controls are evaluated using BB, and any chosen control-continuity equalities are added to the constraints. If tft_f is optimized, it is included in z\mathbf z as well. The resulting finite optimization problem has the form

minimize⁡zcf(xN,tf)+∑k=0N−1cksubject tostage equations,endpoint defects and continuity,boundary, path, and bound constraints.\begin{aligned} \underset{\mathbf{z}}{\operatorname{minimize}}\quad& c_f(\mathbf{x}_N,t_f)+\sum_{k=0}^{N-1}c_k\\ \text{subject to}\quad& \text{stage equations},\\ &\text{endpoint defects and continuity},\\ &\text{boundary, path, and bound constraints}. \end{aligned}

In the preceding chapter’s NLP notation, F(z)F(\mathbf z) is this scalar objective, H(z)=0H(\mathbf z)=\mathbf0 stacks the stage, endpoint, and boundary equalities, and G(z)≤0G(\mathbf z)\leq\mathbf0 stacks the sampled path and bound inequalities. The slope fk,j\mathbf f_{k,j} is a vector, distinct from FF.

The original path and bound constraints apply at every continuous time. The finite NLP can impose them only at selected points, usually its support or collocation nodes. Feasibility at those nodes does not rule out a violation between them, so a continuous replay or dense residual check must follow the optimization.

Every interval constraint touches only local stage variables and neighboring endpoint states. Consequently, most derivatives of the constraints with respect to the decision variables are zero. With variables ordered by time, the nonzero blocks lie near the diagonal of the Jacobian, the matrix of constraint derivatives. NLP solvers can exploit this sparse, block-banded pattern. The arrays AA and bb are numerical constants computed before optimization.

Equivalent differentiation form

The slope-value construction starts from fk,j\mathbf{f}_{k,j} and integrates. Many implementations take the equivalent route of starting from nodal state values and differentiating. The integral of the degree-(s−1)(s-1) slope polynomial has degree at most ss, so take d=sd=s and choose d+1d+1 support nodes σ0,…,σd\sigma_0,\ldots,\sigma_d for the state polynomial. Write ℓrstate\ell_r^{\mathrm{state}} for their cardinal functions to distinguish this support-node basis from the slope-node basis ℓj\ell_j. Denote the support values by x^k,r\widehat{\mathbf x}_{k,r}; these need not be the stage values xk,j\mathbf x_{k,j} at τj\tau_j:

xh(tk+hkτ)=∑r=0dx^k,rℓrstate(τ).\mathbf{x}_h(t_k+h_k\tau) =\sum_{r=0}^{d}\widehat{\mathbf x}_{k,r}\ell_r^{\mathrm{state}}(\tau).

At a collocation node τi\tau_i, the state is a weighted sum of its support values, and its derivative with respect to τ\tau is another weighted sum. The fixed arrays containing these weights are

Eir=ℓrstate(τi),Dir=(ℓrstate)′(τi).E_{ir}=\ell_r^{\mathrm{state}}(\tau_i), \qquad D_{ir}=(\ell_r^{\mathrm{state}})'(\tau_i).

Thus EE evaluates the state polynomial and DD differentiates it. Because d/dt=(1/hk)d/dτd/dt=(1/h_k)d/d\tau, enforcing the ODE at node τi\tau_i gives

∑r=0dDirx^k,r=hkf(∑r=0dEirx^k,r,uk,i,tk+hkτi).\boxed{ \sum_{r=0}^{d}D_{ir}\widehat{\mathbf x}_{k,r} =h_k \mathbf{f}\left( \sum_{r=0}^{d}E_{ir}\widehat{\mathbf x}_{k,r}, \mathbf{u}_{k,i}, t_k+h_k\tau_i \right). }

The left side is the derivative with respect to normalized time, and the factor hkh_k on the right converts the physical-time derivative accordingly. In matrix shorthand, all nodal constraints are DXk=hkFkD\mathsf X_k=h_k\mathsf F_k. Here Xk∈R(d+1)×n\mathsf X_k\in\mathbb R^{(d+1)\times n} has support states as rows, and Fk∈Rs×n\mathsf F_k\in\mathbb R^{s\times n} has stage slopes as rows; neither is a single state vector. Evaluation at the two ends connects this polynomial to the shared mesh states:

xk=∑r=0dℓrstate(0)x^k,r,xk+1=∑r=0dℓrstate(1)x^k,r.\mathbf{x}_{k}=\sum_{r=0}^{d}\ell_r^{\mathrm{state}}(0)\widehat{\mathbf x}_{k,r}, \qquad \mathbf{x}_{k+1}=\sum_{r=0}^{d}\ell_r^{\mathrm{state}}(1)\widehat{\mathbf x}_{k,r}.

When support and collocation nodes coincide, the cardinal property makes EE select the corresponding stored state directly. The slope-value and state-value forms describe the same polynomial construction; one integrates nodal slopes, while the other differentiates nodal states.

This implementation pattern is standard in direct collocation Kelly, 2017Andersson et al., 2019. The official CasADi direct-collocation example constructs fixed differentiation, endpoint, and quadrature arrays from Lagrange polynomials, while the NLP variables remain state and control values.

Both algebraic forms follow the same sequence. Nodal values define a local polynomial, fixed arrays differentiate or integrate it, and equality constraints match the resulting slopes and endpoints to the dynamics. The choice between slope values and state values changes the implementation, not the represented collocation method.

Low-Order Transcriptions

Which familiar integration rules appear when the polynomial and node sets are reduced to their lowest-order choices?

The general construction becomes concrete when only one or two slope values are retained on each interval. These cases recover familiar integration formulas, but the formulas now appear as constraints inside an NLP. For the concrete problems below, fix the mesh and final time. The boundary map h(x0,xN,tN)=0\mathbf h(\mathbf x_0,\mathbf x_N,t_N)=\mathbf0 includes the prescribed initial state and any terminal conditions; g≤0\mathbf g\leq\mathbf0 includes path constraints and state/control bounds. Each displayed program specifies the points where those inequalities are imposed. Additional check points can be included, and a continuous replay still checks the result between nodes.

One slope value: explicit and implicit Euler

A single slope value determines a constant derivative on each interval. Choose a constant control uk,1\mathbf u_{k,1} on that interval as well: uh(tk+hkτ)=uk,1\mathbf u_h(t_k+h_k\tau)=\mathbf u_{k,1}. Different intervals may use different constants. The state is linear even though the control is constant. The following exercise applies the preceding construction to recover the two Euler methods. The solution gives a recipe that also extends to multiple slope nodes.

The complete Euler NLP

Let θ=0\theta=0 for explicit Euler and θ=1\theta=1 for implicit Euler. Both methods optimize the mesh states x0,…,xN\mathbf x_0,\ldots,\mathbf x_N and the NN interval controls uk,1\mathbf u_{k,1}. There are no additional stage-state variables after identifying the sole stage with its endpoint:

min⁡{xk}k=0N, {uk,1}k=0N−1cf(xN,tN)+∑k=0N−1hkc(xk+θ,uk,1,tk+θ)subject toxk+1−xk−hkf(xk+θ,uk,1,tk+θ)=0,g(xk+θ,uk,1,tk+θ)≤0,k=0,…,N−1,h(x0,xN,tN)=0.\begin{aligned} \min_{\{\mathbf x_k\}_{k=0}^N,\,\{\mathbf u_{k,1}\}_{k=0}^{N-1}} \quad &c_f(\mathbf x_N,t_N) +\sum_{k=0}^{N-1}h_kc(\mathbf x_{k+\theta},\mathbf u_{k,1},t_{k+\theta})\\ \text{subject to}\quad &\mathbf x_{k+1}-\mathbf x_k -h_k\mathbf f(\mathbf x_{k+\theta},\mathbf u_{k,1},t_{k+\theta})=\mathbf0,\\ &\mathbf g(\mathbf x_{k+\theta},\mathbf u_{k,1},t_{k+\theta})\leq\mathbf0, \quad k=0,\ldots,N-1,\\ &\mathbf h(\mathbf x_0,\mathbf x_N,t_N)=\mathbf0. \end{aligned}

Here k+θk+\theta selects an endpoint, not an intermediate time. The path constraints use the same endpoint as the dynamics; bounds required at the other endpoint can be imposed there too. The two NLPs differ only in where the slope and cost rate are evaluated. Both are solved for the entire trajectory simultaneously.

Endpoint slope values: trapezoidal transcription

Use continuous piecewise-linear controls, with shared endpoint variables u0,…,uN\mathbf u_0,\ldots,\mathbf u_N. Choose the endpoint collocation nodes τ1=0\tau_1=0 and τ2=1\tau_2=1, and abbreviate the two ODE slopes by

fk=f(xk,uk,tk),fk+1=f(xk+1,uk+1,tk+1).\mathbf{f}_k=\mathbf{f}(\mathbf{x}_k,\mathbf{u}_k,t_k),\qquad \mathbf{f}_{k+1}=\mathbf{f}(\mathbf{x}_{k+1},\mathbf{u}_{k+1},t_{k+1}).

For this endpoint formula, label the cardinal functions by their locations, 0 and 1, rather than by the stage numbers 1 and 2:

ℓ0(τ)=1−τ,ℓ1(τ)=τ.\ell_0(\tau)=1-\tau,\qquad \ell_1(\tau)=\tau.

The derivative interpolant is the line joining the two slopes:

x˙h(tk+hkτ)=(1−τ)fk+τfk+1.\dot{\mathbf{x}}_h(t_k+h_k\tau) =(1-\tau)\mathbf{f}_k+\tau \mathbf{f}_{k+1}.

It equals fk\mathbf{f}_k at τ=0\tau=0 and fk+1\mathbf{f}_{k+1} at τ=1\tau=1. Integrating from the known left state gives the continuous state approximation

xh(tk+hkτ)=xk+hk[(τ−τ22)fk+τ22fk+1].\mathbf{x}_h(t_k+h_k\tau) =\mathbf{x}_k+h_k\left[ \left(\tau-\frac{\tau^2}{2}\right)\mathbf{f}_k +\frac{\tau^2}{2}\mathbf{f}_{k+1} \right].

The state approximation is quadratic, even though an implementation may store only its endpoint states and slopes. Evaluating this polynomial at τ=1\tau=1 and equating it to the stored endpoint produces

xk+1−xk−hk2[f(xk,uk,tk)+f(xk+1,uk+1,tk+1)]=0.\boxed{ \mathbf{x}_{k+1}-\mathbf{x}_k -\frac{h_k}{2} \left[ \mathbf{f}(\mathbf{x}_k,\mathbf{u}_k,t_k) +\mathbf{f}(\mathbf{x}_{k+1},\mathbf{u}_{k+1},t_{k+1}) \right] =\mathbf0. }

The coefficients 1/21/2 are the integrals of the two linear cardinal functions. This is the trapezoidal defect derived in the opening example. Applying the same endpoint weights to the running cost gives

ck=hk2[c(xk,uk,tk)+c(xk+1,uk+1,tk+1)].c_k = \frac{h_k}{2} \left[ c(\mathbf{x}_k,\mathbf{u}_k,t_k) +c(\mathbf{x}_{k+1},\mathbf{u}_{k+1},t_{k+1}) \right].

The two endpoint costs are averaged and multiplied by the interval length. The degree bookkeeping follows directly from integration: a linear derivative interpolant produces a quadratic state interpolant. This distinction is emphasized in the direct-collocation derivation of Kelly (2017).

The complete trapezoidal NLP

The decision variables are the mesh states and controls. Write fk=f(xk,uk,tk)\mathbf f_k=\mathbf f(\mathbf x_k,\mathbf u_k,t_k) and ckrate=c(xk,uk,tk)c_k^{\mathrm{rate}}=c(\mathbf x_k,\mathbf u_k,t_k) for evaluated quantities, not additional optimization variables. Then the transcribed problem is

min⁡{xk,uk}k=0Ncf(xN,tN)+∑k=0N−1hk2(ckrate+ck+1rate)subject toxk+1−xk−hk2(fk+fk+1)=0,k=0,…,N−1,g(xk,uk,tk)≤0,k=0,…,N,h(x0,xN,tN)=0.\begin{aligned} \min_{\{\mathbf x_k,\mathbf u_k\}_{k=0}^{N}}\quad &c_f(\mathbf x_N,t_N) +\sum_{k=0}^{N-1}\frac{h_k}{2} \left(c_k^{\mathrm{rate}}+c_{k+1}^{\mathrm{rate}}\right)\\ \text{subject to}\quad &\mathbf x_{k+1}-\mathbf x_k -\frac{h_k}{2}(\mathbf f_k+\mathbf f_{k+1})=\mathbf0, \quad k=0,\ldots,N-1,\\ &\mathbf g(\mathbf x_k,\mathbf u_k,t_k)\leq\mathbf0, \quad k=0,\ldots,N,\\ &\mathbf h(\mathbf x_0,\mathbf x_N,t_N)=\mathbf0. \end{aligned}

The state between endpoints is the quadratic obtained above, while the control is linear. Shared mesh states and controls connect adjacent pieces; no separate continuity equations are needed in this representation.

Hermite--Simpson Transcription

Can midpoint state and slope information raise the transcription order without requiring a high-degree polynomial over the whole horizon?

Hermite--Simpson extends the trapezoidal construction by adding the midpoint state xk+12\mathbf{x}_{k+\frac12}. Retain the same piecewise-linear control, so its midpoint value is already determined:

uk+12=uk+uk+12.\mathbf u_{k+\frac12}=\frac{\mathbf u_k+\mathbf u_{k+1}}{2}.

Evaluate the midpoint ODE slope using that control:

fk+12=f(xk+12,uk+12,tk+hk2).\mathbf{f}_{k+\frac12}=\mathbf{f}\left( \mathbf{x}_{k+\frac12},\mathbf{u}_{k+\frac12},t_k+\frac{h_k}{2} \right).

The notation xk+12\mathbf x_{k+\frac12} and uk+12\mathbf u_{k+\frac12} denotes values at physical time tk+hk/2t_k+h_k/2, not another mesh endpoint.

The three stage nodes are τ1=0\tau_1=0, τ2=12\tau_2=\tfrac12, and τ3=1\tau_3=1. We label their cardinal functions 0,m,10,m,1 for left endpoint, midpoint, and right endpoint. The derivative interpolant is the quadratic built from the following three cardinal functions:

ℓ0(τ)=2τ2−3τ+1,ℓm(τ)=4τ(1−τ),ℓ1(τ)=2τ2−τ.\ell_0(\tau)=2\tau^2-3\tau+1,\qquad \ell_m(\tau)=4\tau(1-\tau),\qquad \ell_1(\tau)=2\tau^2-\tau.

Integrating each function over the full reference interval gives

b0=16,bm=46,b1=16.b_0=\frac16,\qquad b_m=\frac46,\qquad b_1=\frac16.

These are the familiar Simpson quadrature weights. Substituting them into the general endpoint equation produces the Simpson defect:

xk+1−xk−hk6(fk+4fk+12+fk+1)=0.\boxed{ \mathbf{x}_{k+1}-\mathbf{x}_k -\frac{h_k}{6} \left(\mathbf{f}_k+4\mathbf{f}_{k+\frac12}+\mathbf{f}_{k+1}\right) =\mathbf0. }

The midpoint state must also lie on the cubic obtained by integrating the quadratic derivative. Integration only to τ=12\tau=\tfrac12 gives

xk+12=xk+hk24(5fk+8fk+12−fk+1).\mathbf{x}_{k+\frac12} =\mathbf{x}_k+\frac{h_k}{24} \left(5\mathbf{f}_k+8\mathbf{f}_{k+\frac12}-\mathbf{f}_{k+1}\right).

This form still contains the midpoint slope. The endpoint defect gives

4fk+12=6hk(xk+1−xk)−fk−fk+1.4\mathbf{f}_{k+\frac12} =\frac{6}{h_k}(\mathbf{x}_{k+1}-\mathbf{x}_k)-\mathbf{f}_k-\mathbf{f}_{k+1}.

Substituting this expression into the midpoint equation and collecting the endpoint states and slopes yields

xk+12=xk+xk+12+hk8(fk−fk+1).\boxed{ \mathbf{x}_{k+\frac12} =\frac{\mathbf{x}_k+\mathbf{x}_{k+1}}{2} +\frac{h_k}{8}\left(\mathbf{f}_k-\mathbf{f}_{k+1}\right). }

The midpoint state relation and the definition of fk+12\mathbf{f}_{k+\frac12} together enforce the ODE at the midpoint. A quadratic derivative interpolant integrates to a cubic state interpolant, so Hermite--Simpson is not based on a quadratic state approximation. The name reflects its two ingredients: the state is a cubic Hermite interpolant determined by state and slope information, and its endpoint defect uses Simpson weights.

The complete Hermite--Simpson NLP

With linear controls, optimize mesh states, mesh controls, and midpoint states. For q=kq=k or k+12k+\tfrac12, abbreviate fq=f(xq,uq,tq)\mathbf f_q=\mathbf f(\mathbf x_q,\mathbf u_q,t_q) and cqrate=c(xq,uq,tq)c_q^{\mathrm{rate}}=c(\mathbf x_q,\mathbf u_q,t_q), with tk+12=tk+hk/2t_{k+\frac12}=t_k+h_k/2 and the midpoint control given by the endpoint average. The complete program is

min⁡{xk,uk}k=0N, {xk+12}k=0N−1cf(xN,tN)+∑k=0N−1hk6(ckrate+4ck+12rate+ck+1rate)subject toxk+1−xk−hk6(fk+4fk+12+fk+1)=0,xk+12−xk+xk+12−hk8(fk−fk+1)=0,k=0,…,N−1,g(xq,uq,tq)≤0,q∈{0,12,1,32,…,N},h(x0,xN,tN)=0.\begin{aligned} \min_{\{\mathbf x_k,\mathbf u_k\}_{k=0}^{N},\, \{\mathbf x_{k+\frac12}\}_{k=0}^{N-1}}\quad &c_f(\mathbf x_N,t_N) +\sum_{k=0}^{N-1}\frac{h_k}{6} \left(c_k^{\mathrm{rate}}+4c_{k+\frac12}^{\mathrm{rate}}+c_{k+1}^{\mathrm{rate}}\right)\\ \text{subject to}\quad &\mathbf x_{k+1}-\mathbf x_k -\frac{h_k}{6}(\mathbf f_k+4\mathbf f_{k+\frac12}+\mathbf f_{k+1})=\mathbf0,\\ &\mathbf x_{k+\frac12}-\frac{\mathbf x_k+\mathbf x_{k+1}}{2} -\frac{h_k}{8}(\mathbf f_k-\mathbf f_{k+1})=\mathbf0, \quad k=0,\ldots,N-1,\\ &\mathbf g(\mathbf x_q,\mathbf u_q,t_q)\leq\mathbf0, \quad q\in\{0,\tfrac12,1,\tfrac32,\ldots,N\},\\ &\mathbf h(\mathbf x_0,\mathbf x_N,t_N)=\mathbf0. \end{aligned}

An alternative is to optimize the midpoint control independently. The three control values then define a quadratic on each interval; the midpoint-average relation is removed, and uk+12\mathbf u_{k+\frac12} joins the decision vector. The two state equations and Simpson cost weights remain the same. This changes the admissible controls, so it can change the optimizer’s solution.

The resulting representations can be compared directly. All degrees are upper bounds on each interval; they are not claims about convergence order.

Scheme used hereState degreeControl degreeIndependent values beyond mesh states
Explicit or implicit Euler10One control per interval
Trapezoidal21Shared endpoint controls
Hermite--Simpson, linear control31Shared endpoint controls and midpoint states
Hermite--Simpson, quadratic control32Shared endpoint controls, midpoint states, and midpoint controls

Constructing a Scheme from Its Nodes

How can a program generate these transcriptions from node choices without hand-deriving a new set of defect equations each time?

The same construction generates every scheme in the preceding table. Its inputs are the collocation nodes, the control support nodes, and a choice about control continuity. The number of collocation nodes determines the degree of the slope interpolant and hence the state polynomial. The control support nodes determine the control polynomial independently.

This recipe covers polynomial collocation obtained by interpolating slopes at distinct nodes and integrating them. It includes Gauss, Radau, and Lobatto collocation as well as the low-order examples. An arbitrary Runge--Kutta tableau need not come from such nodes, so specifying nodes does not generate every possible integration method.

The stage controls, slopes, and cost rates in step 3 are expressions in the decision variables. They are recomputed as the optimizer changes those variables; A,b,BA,b,B remain fixed. Automatic differentiation can supply the derivatives of the assembled expressions. If endpoint stages are retained as separate variables, the stage and endpoint equations connect them to the mesh states. Eliminating those copies produces the smaller low-order programs above; keeping both the copies and their defining equations is also valid. Identifying a copy with its endpoint requires removing the resulting duplicate or identically zero equation.

A reusable coefficient generator and residual evaluator

The following function computes A,b,BA,b,B by polynomial arithmetic. The same function accepts any distinct collocation and control support nodes:

collocation_transcription.py
def make_rule(nodes, control_nodes):
    """Precompute integration weights and control evaluation weights.

    A[i,j] = integral from 0 to nodes[i] of slope basis j.
    b[j] = integral from 0 to 1 of slope basis j.
    B[j,r] = control basis r evaluated at collocation node j.
    """
    slope_basis = cardinal_polynomials(nodes)
    control_basis = cardinal_polynomials(control_nodes)
    nodes = np.asarray(nodes, dtype=float)
    antiderivatives = [polynomial.integ() for polynomial in slope_basis]
    A = np.column_stack([p(nodes) - p(0.0) for p in antiderivatives])
    b = np.array([p(1.0) - p(0.0) for p in antiderivatives])
    B = np.column_stack([p(nodes) for p in control_basis])
    return CollocationRule(
        nodes=nodes,
        control_nodes=np.asarray(control_nodes, dtype=float),
        A=A,
        b=b,
        B=B,
        control_left=np.array([p(0.0) for p in control_basis]),
        control_right=np.array([p(1.0) for p in control_basis]),
    )

For example, the choices below recover the four low-order constructions:

from collocation_transcription import make_rule

explicit_euler = make_rule([0.0], [0.0])
implicit_euler = make_rule([1.0], [0.0])
trapezoidal = make_rule([0.0, 1.0], [0.0, 1.0])
hermite_simpson = make_rule([0.0, 0.5, 1.0], [0.0, 1.0])
# An independent midpoint control changes B, not A or b:
hermite_simpson_quadratic_u = make_rule([0.0, 0.5, 1.0], [0.0, 0.5, 1.0])

The implicit-Euler control support node can be 0 even though its collocation node is 1: a constant polynomial has the same value at both. For Hermite--Simpson with linear controls, the generated arrays are

A=[0005/241/3−1/241/62/31/6],b=[1/62/31/6],B=[101/21/201].A=\begin{bmatrix} 0&0&0\\ 5/24&1/3&-1/24\\ 1/6&2/3&1/6 \end{bmatrix},\qquad b=\begin{bmatrix}1/6\\2/3\\1/6\end{bmatrix},\qquad B=\begin{bmatrix}1&0\\1/2&1/2\\0&1\end{bmatrix}.

The middle row of AA gives the midpoint stage equation before elimination; the middle row of BB gives the endpoint-average control. Supplying three control support nodes instead makes BB the identity, allowing an independent midpoint control while leaving the state construction unchanged.

The complete file also supplies transcribed_problem, which evaluates F,G,HF,G,H from arrays of mesh states, stage states, and control support values. Its default allows control jumps; continuous_control=True adds the endpoint-matching equations used by the linear-control examples. A solver wrapper flattens these arrays into z\mathbf z and reshapes each candidate before evaluation. The NumPy evaluator can be used with finite differences; an automatic-differentiation implementation uses the same array operations in its chosen backend. The returned inequality residuals use G≤0G\leq0; negate them for a solver interface that expects nonnegative residuals.

Download the coefficient generator and NLP evaluator

Explicit polynomial coefficients keep this implementation readable at modest degrees. At high degrees, use numerically stable basis evaluation and integration routines; the NLP assembly remains the same.

Optional orientation: Gauss, Radau, and Lobatto nodes

Higher-order schemes often place their nodes at roots of Legendre polynomials or at roots of closely related equations that include prescribed endpoints. These placements produce accurate quadrature rules for a given number of function evaluations. Three names indicate which endpoints are included:

FamilyEndpoints included
GaussNeither endpoint
RadauOne endpoint
LobattoBoth endpoints

Gauss nodes exclude both endpoints, Radau nodes include one, and Lobatto nodes include both. This vocabulary describes node placement, not the coordinate basis used by the NLP. It also does not determine continuity. Adjacent state polynomials are continuous only when they share an endpoint state or are connected by an equality constraint. Endpoint inclusion can make that linkage convenient, but it does not automatically provide state continuity or slope continuity.

The detailed comparison of node families, convergence rates, and adaptive degree selection is deferred. Each family enters the present construction in the same way: its nodes define Lagrange functions, which in turn define fixed differentiation and quadrature operators.

Worked Example: Moving an Overhead Crane While Limiting Residual Sway

How do the nodal variables and trapezoidal defects behave in a constrained motion problem whose terminal state must suppress residual oscillation?

An overhead crane moves a trolley while a payload hangs from a cable. A precomputed trolley command can complete the move and still leave the payload swinging. The comparison uses three precomputed acceleration commands. The unshaped baseline moves the trolley without accounting for the payload. A zero-vibration input shaper modifies that baseline to cancel the nominal oscillation. Direct collocation instead chooses a command using the nonlinear payload dynamics and the motion constraints. All three commands are open loop: they are fixed before the move and do not respond to measurements during execution.

The state is x=(p,v,θ,ω)⊤\mathbf{x}=(p,v,\theta,\omega)^\top, where pp and vv are trolley position and velocity, and θ\theta and ω\omega are payload angle and angular velocity. The scalar control is the commanded trolley acceleration u=au=a. It enters the nonlinear dynamics as

p˙=v,v˙=a,θ˙=ω,ω˙=−gℓsin⁡θ−aℓcos⁡θ−γω.\dot p=v,\qquad \dot v=a,\qquad \dot\theta=\omega,\qquad \dot\omega=-\frac{g}{\ell}\sin\theta-\frac{a}{\ell}\cos\theta-\gamma\omega.

Here gg is gravitational acceleration, ℓ\ell is cable length, and γ\gamma is the damping coefficient. The first two equations describe trolley motion, while the last two describe a damped pendulum driven at its suspension point. Positive trolley acceleration makes the load lag behind, which accounts for the minus sign multiplying aa. The model treats the cable as a rigid, massless link and assumes that the trolley acceleration can be commanded directly.

The trolley and payload start at rest. The goal is to move the trolley 4 m, stop it, and leave the payload hanging vertically without swinging. The nominal cable length is ℓ=1.20\ell=1.20 m. Every command is limited to ∣a∣≤1.60|a|\leq 1.60 m/s2^2, and every command is replayed on the same nonlinear continuous-time plant with a 0.02 s sampling interval. A second replay increases the cable length by 10%10\% without redesigning any command. This second plant tests sensitivity to a simple model mismatch.

Two open-loop baselines

The unshaped baseline uses a symmetric trapezoidal velocity profile, produced by constant acceleration, cruising, and constant deceleration. Its acceleration and deceleration phases excite the payload oscillation because their timing ignores the pendulum period.

An input shaper filters a command into weighted, delayed copies. The delays are chosen so that vibrations excited by the copies cancel one another. For a zero-vibration (ZV) shaper, begin by approximating sin⁡θ≈θ\sin\theta\approx\theta and cos⁡θ≈1\cos\theta\approx1 near the hanging equilibrium. The payload equation then becomes

θ¨+2ζωnθ˙+ωn2θ=−aℓ,ωn=gℓ,ζ=γ2ωn.\ddot\theta+2\zeta\omega_n\dot\theta+\omega_n^2\theta=-\frac{a}{\ell}, \qquad \omega_n=\sqrt{\frac{g}{\ell}}, \qquad \zeta=\frac{\gamma}{2\omega_n}.

Here ωn\omega_n is the undamped natural frequency and ζ\zeta is the damping ratio. For the nominal parameters, ωn=2.86\omega_n=2.86 rad/s and ζ=0.0061\zeta=0.0061. The shaper splits the baseline command a0a_0 into two copies separated by half of the damped oscillation period:

aZV(t)=A1a0(t)+A2a0(t−Td),Td=πωn1−ζ2 .a_{\mathrm{ZV}}(t)=A_1a_0(t)+A_2a_0(t-T_d), \qquad T_d=\frac{\pi}{\omega_n\sqrt{1-\zeta^2}}\,.

The delay makes the vibration caused by the second copy oppose the vibration remaining from the first. Accounting for decay over the delay gives A1=1/(1+K)A_1=1/(1+K), A2=K/(1+K)A_2=K/(1+K), and K=exp⁡[−ζπ/1−ζ2]K=\exp[-\zeta\pi/\sqrt{1-\zeta^2}]. Here Td=1.10T_d=1.10 s and the two weights are approximately 0.505 and 0.495.

Nodal decision variables and trapezoidal defects

The third command is found by solving the trajectory-optimization problem. On N=28N=28 intervals with step hh, the NLP decision vector contains the state

xk=(pk,vk,θk,ωk)⊤\mathbf{x}_k=(p_k,v_k,\theta_k,\omega_k)^\top

and acceleration aka_k at every mesh node. These are polynomial values, not monomial coefficients. Each interval contributes the trapezoidal defect

xk+1−xk−h2[f(xk,ak)+f(xk+1,ak+1)]=0.\mathbf{x}_{k+1}-\mathbf{x}_k -\frac{h}{2}\left[ \mathbf{f}(\mathbf{x}_k,a_k)+\mathbf{f}(\mathbf{x}_{k+1},a_{k+1}) \right]=\mathbf0.

The objective trades payload motion against acceleration magnitude and rapid changes in acceleration. The state and acceleration penalties are collected in the nodal quantity

ckrate=6θk2+0.15ωk2+0.035ak2.c_k^{\mathrm{rate}}=6\theta_k^2+0.15\omega_k^2+0.035a_k^2.

The coefficient on θk2\theta_k^2 penalizes sway most strongly, while the smaller coefficients penalize angular velocity and acceleration. The smooth state-and-control cost uses trapezoidal endpoint weights. The final term penalizes acceleration slew, the rate at which the acceleration command changes. Because the control is piecewise linear, this rate is constant on each interval, giving

J=h(12c0rate+∑k=1N−1ckrate+12cNrate)+0.002h∑k=0N−1(ak+1−akh)2.\mathcal J =h\left(\frac12c_0^{\mathrm{rate}}+\sum_{k=1}^{N-1}c_k^{\mathrm{rate}}+\frac12c_N^{\mathrm{rate}}\right) +0.002h\sum_{k=0}^{N-1} \left(\frac{a_{k+1}-a_k}{h}\right)^2.

The boundary conditions impose x0=(0,0,0,0)⊤\mathbf{x}_0=(0,0,0,0)^\top and xN=(4,0,0,0)⊤\mathbf{x}_N=(4,0,0,0)^\top, so both the trolley and payload finish at rest. The nodal bounds impose ∣ak∣≤1.60|a_k|\leq1.60 m/s2^2, ∣vk∣≤1.50|v_k|\leq1.50 m/s, and ∣θk∣≤15∘|\theta_k|\leq15^\circ. Because these bounds are imposed only at nodes, a dense replay remains necessary to check the path between nodes.

The ZV shaper is tailored to one frequency, so it should leave the least residual sway when the cable length matches its design model. The collocation solution uses the full nonlinear nominal model and handles all constraints at once, but it is also open loop and has no explicit robustness guarantee. The cable-length test therefore measures sensitivity to one model mismatch; it does not establish that either method is robust in general.

Figure 6:All three commands move the trolley through the same four-metre task on the nonlinear plant. The unshaped command leaves a large oscillation. The ZV shaper nearly cancels the nominal mode, while direct collocation reaches the terminal state with a smoother, lower-effort command. The lower panel replays the unchanged commands after increasing cable length by 10 percent. Hatched bars denote the mismatched plant.

<Figure size 825x750 with 3 Axes>

The ZV shaper produces the smallest nominal residual sway because the simulated plant closely matches the single oscillatory mode used to design it. The collocation command uses less squared acceleration than either baseline and keeps residual sway below one degree in both replays. The unshaped command completes the trolley move but leaves several degrees of oscillation. Cable-length mismatch increases the ZV residual substantially, while the collocation command degrades more gradually for this particular perturbation.

The table reports continuous-plant measurements rather than node values from the nonlinear program. Residual sway is the largest absolute angle after the common command horizon.

Loading...

The animation uses the same high-accuracy nonlinear validation trajectories as the figure. It does not replay the collocation polynomial itself.

Figure 7:Continuous nonlinear replay of the unshaped, zero-vibration-shaped, and direct-collocation commands. All panels use the same spatial and temporal scales.

Loading...
Inspect the direct-transcription implementation
crane_control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def solve_direct_collocation(
    params: CraneParameters | None = None,
    *,
    intervals: int = 28,
    horizon: float | None = None,
    max_iterations: int = 350,
) -> CollocationSolution:
    """Solve a constrained nonlinear point-to-point transcription.

    States and accelerations at every node are decision variables.  Trapezoidal
    defects enforce the nonlinear dynamics, while boundary and path constraints
    are imposed directly on the node values.
    """

    params = params or CraneParameters()
    params.validate()
    if intervals < 8:
        raise ValueError("intervals must be at least eight")

    move = TrapezoidalMove(
        params.target_position,
        params.profile_acceleration,
        params.profile_max_speed,
    )
    shaper = ZeroVibrationShaper.from_parameters(params)
    if horizon is None:
        horizon = move.duration + shaper.delay
    if horizon <= 0.0:
        raise ValueError("horizon must be positive")

    node_time = np.linspace(0.0, horizon, intervals + 1)
    step = horizon / intervals
    state_guess, acceleration_guess = _initial_guess(params, node_time, move, shaper)
    initial = _pack(state_guess, acceleration_guess)

    initial_state = np.zeros(4)
    terminal_state = np.array([params.target_position, 0.0, 0.0, 0.0])

    def objective(vector: np.ndarray) -> float:
        state, acceleration = _unpack(vector, intervals)
        return _transcription_objective(state, acceleration, step)

    def equality(vector: np.ndarray) -> np.ndarray:
        state, acceleration = _unpack(vector, intervals)
        defects = np.empty((intervals, 4))
        for k in range(intervals):
            left = crane_dynamics(state[k], acceleration[k], params)
            right = crane_dynamics(state[k + 1], acceleration[k + 1], params)
            defects[k] = state[k + 1] - state[k] - 0.5 * step * (left + right)
        return np.concatenate(
            [state[0] - initial_state, defects.ravel(), state[-1] - terminal_state]
        )

    nodes = intervals + 1
    lower_state = np.tile(
        np.array([-0.25, -params.velocity_limit, -params.sway_limit, -2.0]),
        (nodes, 1),
    )
    upper_state = np.tile(
        np.array(
            [params.target_position + 0.25, params.velocity_limit, params.sway_limit, 2.0]
        ),
        (nodes, 1),
    )
    lower = _pack(lower_state, np.full(nodes, -params.acceleration_limit))
    upper = _pack(upper_state, np.full(nodes, params.acceleration_limit))

    result = minimize(
        objective,
        initial,
        method="SLSQP",
        bounds=list(zip(lower, upper)),
        constraints={"type": "eq", "fun": equality},
        options={"maxiter": max_iterations, "ftol": 2e-10, "disp": False},
    )
    state, acceleration = _unpack(result.x, intervals)
    max_defect = float(np.max(np.abs(equality(result.x))))
    success = bool(result.success and max_defect < 2e-5)
    if not success:
        raise RuntimeError(
            "crane direct collocation failed: "
            f"{result.message}; maximum equality residual {max_defect:.3e}"
        )
    return CollocationSolution(
        time=node_time,
        state=state,
        acceleration=acceleration,
        objective=float(result.fun),
        max_defect=max_defect,
        success=success,
        message=str(result.message),
    )

Download the complete crane experiment

The optimization checks algebraic defects, bounds, and endpoint conditions at the nodes. The separate nonlinear replay checks what happens between those nodes. A small nodal defect is evidence that the discrete NLP was solved accurately; it is not, by itself, evidence that the mesh resolves the continuous dynamics.

The comparison does not establish that collocation always outperforms input shaping. The ZV calculation is inexpensive and can nearly cancel residual vibration when a lightly damped mode is accurately known. Direct collocation becomes useful when several state and actuator constraints must be handled together. All three commands remain open loop here. Feedback or receding-horizon replanning would be needed to react to unmeasured disturbances during the move.

Exercises

Summary and Outlook

Direct collocation turns an optimization over whole functions into an optimization over finitely many state and control values. These nodal values define polynomial segments. Algebraic defect constraints then require each segment to agree with the ODE at selected points.

Each polynomial has two equivalent descriptions: basis coefficients or values at nodes,

p(τ)=∑jajϕj(τ)=∑jyjℓj(τ),y=Va.p(\tau)=\sum_j a_j\phi_j(\tau) =\sum_j y_j\ell_j(\tau), \qquad \mathbf y=V\mathbf a.

Direct collocation uses the nodal description because the stored values have an immediate physical meaning. Lagrange cardinal functions turn them into fixed operators for computing derivatives, endpoints, and integrals. Although this construction resembles polynomial fitting, the nodal values are optimization variables rather than noisy observations, and the ODE residual is an equality constraint rather than a regression loss.

Interpolating one left or right slope gives explicit or implicit Euler and a linear state approximation. Interpolating both endpoint slopes gives the trapezoidal defect and a quadratic state approximation. Adding the midpoint slope gives Simpson weights, the Hermite--Simpson midpoint relation, and a cubic state approximation.

Across many intervals, each defect involves only neighboring endpoints and local stage values. Most entries in the constraint Jacobian are therefore zero, which allows an NLP solver to exploit a sparse, block-banded structure. The overhead-crane example also shows why solving the NLP is not the final check: constraints that hold at the nodes may still be violated between them. A dense, independent simulation should therefore follow the optimization. Can the same finite-horizon problem respond when that replay reveals a state different from the prediction? Receding-horizon control turns the open-loop transcription into feedback by replanning from each measurement.

References
  1. Kelly, M. (2017). An Introduction to Trajectory Optimization: How to Do Your Own Direct Collocation. SIAM Review, 59(4), 849–904. 10.1137/16M1062569
  2. Andersson, J. A. E., Gillis, J., Horn, G., Rawlings, J. B., & Diehl, M. (2019). CasADi: A Software Framework for Nonlinear Optimization and Optimal Control. Mathematical Programming Computation, 11(1), 1–36. 10.1007/s12532-018-0139-4