The preceding chapter formulated trajectory optimization for systems that are already discrete in time. 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 algebraic constraints.
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¶
What is the smallest transcription that turns one differential equation on one interval into a finite algebraic defect?
Consider a point that must move from to . Its velocity is the control, so
and the objective penalizes squared control effort,
Both and are unknown functions. As a first finite approximation, retain only their endpoint values and let the control vary linearly between and . Integrating 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, and , 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 . Setting the interval width to recovers the chapter’s defect .
Figure 2:A linear control connects and across an interval of width . The rectangle and triangle sum to . Because , this area equals .
The resulting equality becomes the defect constraint
This algebraic equation is called a defect constraint: its left-hand side measures the mismatch between the endpoint change and the change predicted by the approximated dynamics. Applying the same endpoint approximation to the running cost gives the finite nonlinear program
The boundary conditions reduce the defect to . Substituting into the objective gives
The squared term is minimized at , which also gives . The resulting interpolation is the exact solution and .
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?
A continuous-time optimal-control problem can be written in Bolza form:
Here is the state, is the control, is a terminal cost, and is a running cost. The equality imposes endpoint conditions, while represents constraints that must hold along the path. Setting gives the Mayer special case, while setting 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:
| Strategy | Finite decision variables | Treatment of the ODE |
|---|---|---|
| Shooting | Control parameters and, in multiple shooting, selected boundary states | A time integrator advances the state sequentially inside each shooting interval |
| Direct collocation | State and control values at selected nodes | Algebraic 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
be a mesh. On each interval, the normalized coordinate is , or equivalently
Every physical interval is thereby mapped to the same reference interval . Differentiation and integration formulas can be constructed once on this reference interval; the length 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 form the space
This space, denoted by , has dimension . Choosing a basis gives coefficient coordinates
The monomial choice is familiar, but it is only a coordinate system. The polynomial is the function , not its particular list of coefficients.
The same polynomial can instead be identified by its values. Choose distinct points
and record
These points are called support nodes because the stored values at the nodes determine the polynomial between them. For degree one with support nodes 0 and 1, the construction is already familiar:
The multiplier equals one at the first node and zero at the second; does the reverse. For any set of distinct support nodes, the Lagrange cardinal function is the degree- polynomial with this same selection property: it equals one at node and zero at every other support node. Its formula is
At a support node , one factor in the numerator is zero unless . When , every numerator equals its corresponding denominator. Consequently,
where the Kronecker delta equals one when and zero otherwise. The cardinal functions therefore reconstruct the polynomial from its nodal values:
The uniqueness of this reconstruction follows from a basic root-counting argument. If two polynomials in have the same nodal values, their difference has distinct roots. A nonzero polynomial of degree at most cannot have that many roots, so the two polynomials must be identical.
The coefficient and nodal descriptions are related by the evaluation matrix
Distinct support nodes make invertible by the same root-counting argument. Thus and are two coordinate vectors for one polynomial, rather than two different approximations.
For example, take and the nodes . In monomial coordinates,
whereas the nodal coordinates are
Both vectors describe exactly the same quadratic. Direct collocation uses coordinates like : 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 at the support nodes gives . Direct collocation stores the nodal vector ; the fixed operators and then return its nodal derivatives and exact integral without adding optimization variables.

Polynomial space, basis, and nodes are different choices¶
The construction separates three decisions that are easy to conflate:
The polynomial space specifies which functions are available.
The basis specifies coordinates for a member of that space. Monomial and Lagrange bases span the same .
The nodes specify where values, residuals, or integrals are evaluated.
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 both produce polynomials, but they answer different questions. Four exact values at four distinct nodes determine one cubic interpolant. Twenty noisy measurements do not generally lie on one cubic, so cubic regression instead chooses the coefficients that minimize the aggregate squared residual. Write for the matrix obtained by evaluating the chosen polynomial basis at the supplied input points. The two algebraic problems are then compared below.
| Polynomial interpolation | Least-squares regression | |
|---|---|---|
| Input | Exact value conditions | Usually noisy or overdetermined observations |
| Algebraic problem | Satisfy exactly | Minimize |
| Residual | Zero when the value conditions uniquely determine a polynomial | Generally nonzero |
| Typical purpose | Represent a function from exact nodal data | Estimate a trend or conditional mean |
If 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:The panels use the same six values. On the left they are treated as six exact conditions for a degree-five interpolant, so every residual is zero. On the right they are treated as six observations for a three-parameter quadratic regression, so the fit trades errors across observations.

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¶
Once the nodes and basis are fixed, can differentiation and integration be reduced to precomputed linear maps on nodal values?
The ODE and the running cost require more than values of an interpolating polynomial. The ODE uses derivatives, and the cost and state update use integrals. Since
both operations are linear functions of the nodal vector . Differentiating and then evaluating at a node gives
while integration over the reference interval gives
The resulting differentiation matrix and integration weights depend only on the chosen nodes. They can be computed before the optimization begins.
For the three support nodes , the cardinal functions are
The factored forms come directly from the general product formula. Each function takes the value one at the node named by its subscript and zero at the other two nodes. Differentiating them at all three nodes gives
Thus a matrix-vector product turns the three stored values into the three nodal derivatives. Integrating the same cardinal functions gives
The row turns the same three values into the exact integral of their quadratic interpolant. The matrix differentiates every polynomial in exactly, and 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 role | What it does |
|---|---|
| Support node | Supplies coordinates that define a polynomial |
| Collocation node | Supplies a point where the ODE residual is constrained |
| Quadrature node | Supplies 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?
The previous section constructed differentiation and integration operators for an arbitrary polynomial. To impose an ODE, first choose collocation nodes on . At each node, the differential equation prescribes the state slope. Denote that slope on interval by
for . Here and are the state and control at the node. Let be the Lagrange cardinal function associated with the collocation nodes . The nodal slopes then define the derivative interpolant
This polynomial agrees with the ODE slope at every collocation node. Integrating it from the left endpoint to node gives the state value there:
The factor appears because . These equalities are called stage equations; a stage is an interval-local state and control evaluation used by the transcription. Integrating the same derivative polynomial across the full reference interval gives the right endpoint:
The coefficients are the areas under the cardinal functions. The endpoint equation is both an integration formula and a defect constraint: its residual compares the stored endpoint with the endpoint predicted from and the nodal slopes. If is shared with the next interval, it also enforces state continuity. Otherwise an explicit equality must connect the two interval representations. Merely including an endpoint among the collocation nodes does not create continuity by itself.
A quadrature rule approximates an integral by a weighted sum of function values. Reusing the collocation nodes and their full-interval weights gives the interval running-cost approximation
Thus the running cost is evaluated at the same local stages as the vector field. Different quadrature nodes could be used instead; the state and control polynomials would simply be evaluated there.
After all intervals are assembled, collect the nodal states and controls into the decision vector
The resulting finite optimization problem has the form
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 and are numerical constants computed before optimization.
Equivalent differentiation form¶
The slope-value construction starts from and integrates. Many implementations take the equivalent route of starting from nodal state values and differentiating. Let be support nodes for a state polynomial, and denote their cardinal functions by to avoid confusing them with the running cost :
At a collocation node , the state is a weighted sum of its support values, and its derivative with respect to is another weighted sum. The fixed arrays containing these weights are
Thus evaluates the state polynomial and differentiates it. Because , enforcing the ODE at node gives
The left side is the derivative with respect to normalized time, and the factor on the right converts the physical-time derivative accordingly. In matrix shorthand, all nodal constraints are . The right endpoint is evaluated with another fixed row:
When support and collocation nodes coincide, the cardinal property makes 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.
One slope value: explicit and implicit Euler¶
With the single left collocation node , the only cardinal function is . The derivative interpolant is therefore the constant slope . Its integration weight is , so the endpoint defect is
This is explicit Euler. The stored right endpoint is constrained to equal the result of advancing from the left endpoint with its local slope. Because the derivative approximation is constant, its integral is a linear state approximation on the interval.
With the single right collocation node , the constant slope is evaluated at the unknown right endpoint. The same integration weight gives
This is implicit Euler. In sequential simulation, the occurrence of inside requires a nonlinear solve at each step. In direct transcription, is already an optimization variable, so the relation is imposed as one of the simultaneous equality constraints.
Endpoint slope values: trapezoidal transcription¶
Choose the endpoint collocation nodes and , and abbreviate the two ODE slopes by
The cardinal functions used to interpolate these derivative values are
The derivative interpolant is the line joining the two slopes:
It equals at and at . Integrating from the known left state gives the continuous state approximation
The state approximation is quadratic, even though an implementation may store only its endpoint states and slopes. Evaluating this polynomial at and equating it to the stored endpoint produces
The coefficients 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
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).
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 , control , and ODE slope
The derivative is now specified at , so its interpolant is the quadratic built from the following three cardinal functions:
Integrating each function over the full reference interval gives
These are the familiar Simpson quadrature weights. Substituting them into the general endpoint equation produces the Simpson defect:
The midpoint state must also lie on the cubic obtained by integrating the quadratic derivative. Integration only to gives
This form still contains the midpoint slope. The endpoint defect gives
Substituting this expression into the midpoint equation and collecting the endpoint states and slopes yields
The midpoint state relation and the definition of 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.
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:
| Family | Endpoints included |
|---|---|
| Gauss | Neither endpoint |
| Radau | One endpoint |
| Lobatto | Both 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 , where and are trolley position and velocity, and and are payload angle and angular velocity. The commanded trolley acceleration enters the nonlinear dynamics as
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 . 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 m. Every command is limited to m/s, 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 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 and near the hanging equilibrium. The payload equation then becomes
Here is the undamped natural frequency and is the damping ratio. For the nominal parameters, rad/s and . The shaper splits the baseline command into two copies separated by half of the damped oscillation period:
The delay makes the vibration caused by the second copy oppose the vibration remaining from the first. Accounting for decay over the delay gives , , and . Here 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 intervals with step , the NLP decision vector contains the state
and acceleration at every mesh node. These are polynomial values, not monomial coefficients. Each interval contributes the trapezoidal defect
The objective trades payload motion against acceleration magnitude and rapid changes in acceleration. The first two terms are collected in the nodal quantity
The coefficient on 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
The boundary conditions impose and , so both the trolley and payload finish at rest. The nodal bounds impose m/s, m/s, and . 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 5: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.

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.
The animation uses the same high-accuracy nonlinear validation trajectories as the figure. It does not replay the collocation polynomial itself.
Figure 6:Continuous nonlinear replay of the unshaped, zero-vibration-shaped, and direct-collocation commands. All panels use the same spatial and temporal scales.
Inspect the direct-transcription implementation
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 93def 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¶
Solution to Exercise 1
Solution to Exercise 2
Problems 1 and 4 are interpolation problems; the least-squares formulation in problem 4 has a zero-residual interpolating solution. Problem 2 is regression. Problem 3 is neither statistical regression nor interpolation of observations: the unknown nodal values define an interpolating polynomial, and collocation adds equality constraints that select those values.
Solution to Exercise 3
Solution to Exercise 4
One node gives the constant derivative interpolant or . Integration yields the explicit or implicit Euler defect and a degree-one state. With endpoint nodes, . Its integral at is , which gives the trapezoidal defect. The linear derivative integrates to a degree-two state.
Solution to Exercise 5
Three distinct slope values define a quadratic derivative interpolant. Integrating that quadratic adds one degree, so the state is cubic. Integrating the cardinal functions over gives and hence the Simpson defect. Integrating to gives ; eliminating the midpoint slope with the endpoint defect gives
Solution to Exercise 6
The NLP defect measures its equality constraints only at the selected nodes. A coarse polynomial can satisfy those constraints while failing to resolve rapid behavior between them. Evaluate the ODE residual and path constraints on a dense grid, preferably using an independent high-accuracy replay. Refine the offending intervals or raise the local approximation degree, then solve and validate again. Tightening an already small NLP tolerance does not fix representation error.
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,
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.
- Kelly, M. (2017). An Introduction to Trajectory Optimization: How to Do Your Own Direct Collocation. SIAM Review, 59(4), 849–904. 10.1137/16M1062569
- 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