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.

Global Assembly of Multiple-Interval LGR Transcriptions

This section completes the derivation of the multiple-interval Legendre–Gauss–Radau (LGR) pseudospectral method. The preceding development established the local state approximation, local differentiation matrix, local quadrature rule, and collocation equations on each mesh interval. The present chapter assembles those local objects into a single global nonlinear programming problem.

The central result is that the multiple-interval method retains almost exactly the same mathematical form as the single-interval LGR method:

DX=tft02F,\boldsymbol{D}\boldsymbol{X} = \frac{t_f-t_0}{2}\boldsymbol{F},

but the global differentiation matrix is sparse and is constructed from local interval matrices whose adjacent blocks share one state column.

The chapter develops:

Transformed Time Domain and Mesh

The physical time interval

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

is mapped to the fixed domain

s[1,1]s\in[-1,1]

using

s=2(tt0)tft01.s = \frac{2(t-t_0)}{t_f-t_0}-1.

The inverse mapping is

t(s)=tft02s+tf+t02.t(s) = \frac{t_f-t_0}{2}s + \frac{t_f+t_0}{2}.

The transformed dynamics are

dxds=tft02f(x(s),u(s),t(s),p).\frac{\,\mathrm{d}\boldsymbol{x}}{\,\mathrm{d} s} = \frac{t_f-t_0}{2} \boldsymbol{f}\left( \boldsymbol{x}(s),\boldsymbol{u}(s),t(s),\boldsymbol{p} \right).

The transformed domain is divided into KK mesh intervals:

1=s0<s1<<sK1<sK=1.-1=s_0<s_1<\cdots<s_{K-1}<s_K=1.

The kkth interval is

Sk=[sk1,sk].\mathcal{S}_k=[s_{k-1},s_k].

The mesh points are fixed during a single nonlinear programming solve. They may be changed between solves during mesh refinement.

Local LGR Approximation

Let interval kk contain NkN_k LGR collocation points:

s1(k),s2(k),,sNk(k).s_1^{(k)},s_2^{(k)},\ldots,s_{N_k}^{(k)}.

Forward LGR includes the left interval endpoint but excludes the right endpoint:

s1(k)=sk1,sNk(k)<sk.s_1^{(k)}=s_{k-1}, \qquad s_{N_k}^{(k)}<s_k.

The additional state point is

sNk+1(k)=sk.s_{N_k+1}^{(k)}=s_k.

The state approximation is

x(k)(s)X(k)(s)=i=1Nk+1Xi(k)i(k)(s),\boldsymbol{x}^{(k)}(s) \approx \boldsymbol{X}^{(k)}(s) = \sum_{i=1}^{N_k+1} \boldsymbol{X}_i^{(k)} \ell_i^{(k)}(s),

where

i(k)(s)=j=1jiNk+1ssj(k)si(k)sj(k).\ell_i^{(k)}(s) = \prod_{\substack{j=1\\j\neq i}}^{N_k+1} \frac{s-s_j^{(k)}}{s_i^{(k)}-s_j^{(k)}}.

The control is represented at only the NkN_k collocation points:

Ui(k)u(si(k)),i=1,,Nk.\boldsymbol{U}_i^{(k)} \approx \boldsymbol{u}\left(s_i^{(k)}\right), \qquad i=1,\ldots,N_k.

Local Differentiation Matrix

Differentiating the state approximation gives

dX(k)ds=i=1Nk+1Xi(k)di(k)ds.\frac{\,\mathrm{d}\boldsymbol{X}^{(k)}}{\,\mathrm{d} s} = \sum_{i=1}^{N_k+1} \boldsymbol{X}_i^{(k)} \frac{\,\mathrm{d}\ell_i^{(k)}}{\,\mathrm{d} s}.

At collocation node sj(k)s_j^{(k)},

dX(k)dss=sj(k)=i=1Nk+1Dji(k)Xi(k),\left. \frac{\,\mathrm{d}\boldsymbol{X}^{(k)}}{\,\mathrm{d} s} \right|_{s=s_j^{(k)}} = \sum_{i=1}^{N_k+1} D_{ji}^{(k)} \boldsymbol{X}_i^{(k)},

where

Dji(k)=di(k)dss=sj(k).D_{ji}^{(k)} = \left. \frac{\,\mathrm{d}\ell_i^{(k)}}{\,\mathrm{d} s} \right|_{s=s_j^{(k)}}.

Thus,

D(k)RNk×(Nk+1).\boldsymbol{D}^{(k)} \in \mathbb{R}^{N_k\times(N_k+1)}.

The local collocation equations are

i=1Nk+1Dji(k)Xi(k)=tft02f(Xj(k),Uj(k),tj(k),p).\boxed{ \sum_{i=1}^{N_k+1} D_{ji}^{(k)} \boldsymbol{X}_i^{(k)} = \frac{t_f-t_0}{2} \boldsymbol{f}\left( \boldsymbol{X}_j^{(k)}, \boldsymbol{U}_j^{(k)}, t_j^{(k)}, \boldsymbol{p} \right). }

These equations hold for

j=1,,Nk.j=1,\ldots,N_k.

State Continuity at Mesh Points

The final state of interval kk and the initial state of interval k+1k+1 represent the same physical state:

XNk+1(k)=X1(k+1).\boxed{ \boldsymbol{X}_{N_k+1}^{(k)} = \boldsymbol{X}_1^{(k+1)}. }

This relation can be implemented in two ways.

Explicit Continuity Constraints

Retain separate variables and impose

XNk+1(k)X1(k+1)=0.\boldsymbol{X}_{N_k+1}^{(k)} - \boldsymbol{X}_1^{(k+1)} = \boldsymbol{0}.

Shared Interface Variables

Use one NLP variable for both quantities:

XNk+1(k)X1(k+1).\boldsymbol{X}_{N_k+1}^{(k)} \equiv \boldsymbol{X}_1^{(k+1)}.

The shared-variable formulation is particularly elegant because it creates the overlapping-column structure of the global differentiation matrix.

Control Representation at Mesh Points

The forward LGR scheme does not contain a control at the right endpoint of interval kk. It does contain a control at the left endpoint of interval k+1k+1.

Therefore, the control at an interior mesh point has one representation:

U1(k+1).\boldsymbol{U}_1^{(k+1)}.

There is no second control variable

UNk+1(k)\boldsymbol{U}_{N_k+1}^{(k)}

because the terminal state point is not a collocation point.

This property avoids an artificial double-valued control at the interface.

The only point on the full transformed domain without a control variable is the final endpoint:

sK=1.s_K=1.

Total Number of LGR Points

Define the total number of collocation points:

N=k=1KNk.\boxed{ N = \sum_{k=1}^{K}N_k. }

There are:

The additional state point is the terminal point of the final interval.

Global Collocation-Point Vector

Stack the local LGR nodes in monotonically increasing order:

S~=[s1(1)sN1(1)s1(2)sN2(2)s1(K)sNK(K)]RN.\widetilde{\boldsymbol{S}} = \begin{bmatrix} s_1^{(1)}\\ \vdots\\ s_{N_1}^{(1)}\\ s_1^{(2)}\\ \vdots\\ s_{N_2}^{(2)}\\ \vdots\\ s_1^{(K)}\\ \vdots\\ s_{N_K}^{(K)} \end{bmatrix} \in\mathbb{R}^N.

The complete state-node vector includes the terminal point:

S=[S~sNK+1(K)]=[S~1]RN+1.\boldsymbol{S} = \begin{bmatrix} \widetilde{\boldsymbol{S}}\\ s_{N_K+1}^{(K)} \end{bmatrix} = \begin{bmatrix} \widetilde{\boldsymbol{S}}\\ 1 \end{bmatrix} \in\mathbb{R}^{N+1}.

All entries in S~\widetilde{\boldsymbol{S}} are collocation points. The final entry of S\boldsymbol{S} is not a collocation point.

Global Weight Vector

For interval kk, let the LGR quadrature weights be

w1(k),,wNk(k).w_1^{(k)},\ldots,w_{N_k}^{(k)}.

Stack them:

W=[w1(1)wN1(1)w1(2)wN2(2)w1(K)wNK(K)]RN.\boxed{ \boldsymbol{W} = \begin{bmatrix} w_1^{(1)}\\ \vdots\\ w_{N_1}^{(1)}\\ w_1^{(2)}\\ \vdots\\ w_{N_2}^{(2)}\\ \vdots\\ w_1^{(K)}\\ \vdots\\ w_{N_K}^{(K)} \end{bmatrix} \in\mathbb{R}^N. }

There is no weight corresponding to the terminal state point.

Global State Matrix

Assume there are nxn_x states. The unique state values are stacked as

X=[X1(1)XN1(1)X1(2)XN2(2)X1(K)XNK(K)XNK+1(K)].\boldsymbol{X} = \begin{bmatrix} \boldsymbol{X}_1^{(1)}\\ \vdots\\ \boldsymbol{X}_{N_1}^{(1)}\\ \boldsymbol{X}_1^{(2)}\\ \vdots\\ \boldsymbol{X}_{N_2}^{(2)}\\ \vdots\\ \boldsymbol{X}_1^{(K)}\\ \vdots\\ \boldsymbol{X}_{N_K}^{(K)}\\ \boldsymbol{X}_{N_K+1}^{(K)} \end{bmatrix}.

With one row per state node,

XR(N+1)×nx.\boldsymbol{X}\in\mathbb{R}^{(N+1)\times n_x}.

The interface states are not duplicated. For example,

XN1+1(1)=X1(2)\boldsymbol{X}_{N_1+1}^{(1)} = \boldsymbol{X}_1^{(2)}

is represented by one shared row in the global state matrix.

Collocation-State Matrix

Path constraints and dynamics are evaluated only at collocation nodes. Define

X~=X(1:N,:)RN×nx.\boxed{ \widetilde{\boldsymbol{X}} = \boldsymbol{X}(1:N,:) \in\mathbb{R}^{N\times n_x}. }

Thus, X~\widetilde{\boldsymbol{X}} excludes the final noncollocated state.

Global Control Matrix

Assume there are nun_u controls. Stack the control values:

U=[U1(1)UN1(1)U1(2)UN2(2)U1(K)UNK(K)]RN×nu.\boldsymbol{U} = \begin{bmatrix} \boldsymbol{U}_1^{(1)}\\ \vdots\\ \boldsymbol{U}_{N_1}^{(1)}\\ \boldsymbol{U}_1^{(2)}\\ \vdots\\ \boldsymbol{U}_{N_2}^{(2)}\\ \vdots\\ \boldsymbol{U}_1^{(K)}\\ \vdots\\ \boldsymbol{U}_{N_K}^{(K)} \end{bmatrix} \in \mathbb{R}^{N\times n_u}.

The number of control rows equals the number of global collocation points.

Global Dynamics Matrix

Define

F=[f(X1(1),U1(1),t1(1),p)f(XN1(1),UN1(1),tN1(1),p)f(XNK(K),UNK(K),tNK(K),p)].\boldsymbol{F} = \begin{bmatrix} \boldsymbol{f}\left( \boldsymbol{X}_1^{(1)},\boldsymbol{U}_1^{(1)},t_1^{(1)},\boldsymbol{p} \right)\\ \vdots\\ \boldsymbol{f}\left( \boldsymbol{X}_{N_1}^{(1)},\boldsymbol{U}_{N_1}^{(1)},t_{N_1}^{(1)},\boldsymbol{p} \right)\\ \vdots\\ \boldsymbol{f}\left( \boldsymbol{X}_{N_K}^{(K)},\boldsymbol{U}_{N_K}^{(K)},t_{N_K}^{(K)},\boldsymbol{p} \right) \end{bmatrix}.

Therefore,

FRN×nx.\boldsymbol{F} \in \mathbb{R}^{N\times n_x}.

Assembly of the Global Differentiation Matrix

Each local matrix is

D(k)RNk×(Nk+1).\boldsymbol{D}^{(k)} \in \mathbb{R}^{N_k\times(N_k+1)}.

The final state column of interval kk is the initial state column of interval k+1k+1. Therefore, adjacent local matrices overlap in one global column.

The global matrix has dimension

DRN×(N+1).\boxed{ \boldsymbol{D} \in \mathbb{R}^{N\times(N+1)}. }

It is not a conventional block-diagonal matrix because adjacent blocks share one column. It is more accurately described as a block-sparse matrix with one-column overlap.

Two-Interval Example

For two intervals with N1N_1 and N2N_2 points:

D=[D(1)00D(2)]with shared interface column.\boldsymbol{D} = \begin{bmatrix} \boldsymbol{D}^{(1)} & \boldsymbol{0}\\ \boldsymbol{0} & \boldsymbol{D}^{(2)} \end{bmatrix}_{\text{with shared interface column}}.

More explicitly, partition

D(1)=[DA(1)db(1)],\boldsymbol{D}^{(1)} = \begin{bmatrix} \boldsymbol{D}_A^{(1)} & \boldsymbol{d}_b^{(1)} \end{bmatrix},

where

DA(1)RN1×N1,db(1)RN1.\boldsymbol{D}_A^{(1)}\in\mathbb{R}^{N_1\times N_1}, \qquad \boldsymbol{d}_b^{(1)}\in\mathbb{R}^{N_1}.

Similarly,

D(2)=[da(2)DB(2)].\boldsymbol{D}^{(2)} = \begin{bmatrix} \boldsymbol{d}_a^{(2)} & \boldsymbol{D}_B^{(2)} \end{bmatrix}.

Then

D=[DA(1)db(1)00da(2)DB(2)].\boxed{ \boldsymbol{D} = \begin{bmatrix} \boldsymbol{D}_A^{(1)} & \boldsymbol{d}_b^{(1)} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{d}_a^{(2)} & \boldsymbol{D}_B^{(2)} \end{bmatrix}. }

The central column corresponds to the shared interface state.

General KK-Interval Structure

The global matrix has the schematic form

D=[D(1)D(2)D(K)],\boldsymbol{D} = \begin{bmatrix} \boxed{\boldsymbol{D}^{(1)}} & & & \\ & \boxed{\boldsymbol{D}^{(2)}} & & \\ & & \ddots & \\ & & & \boxed{\boldsymbol{D}^{(K)}} \end{bmatrix},

where neighboring boxes overlap by one state column.

This structure yields a sparse matrix even when the total number of collocation points is large.

Global Collocation Equations

The local collocation equations from all mesh intervals combine into

DX=tft02F.\boxed{ \boldsymbol{D}\boldsymbol{X} = \frac{t_f-t_0}{2}\boldsymbol{F}. }

Equivalently, define the global defect matrix:

Δ=DXtft02F.\boxed{ \boldsymbol{\Delta} = \boldsymbol{D}\boldsymbol{X} - \frac{t_f-t_0}{2}\boldsymbol{F}. }

The NLP enforces

Δ=0.\boldsymbol{\Delta}=\boldsymbol{0}.

The dimensions are

DRN×(N+1),XR(N+1)×nx,FRN×nx,ΔRN×nx.\begin{aligned} \boldsymbol{D}&\in\mathbb{R}^{N\times(N+1)},\\ \boldsymbol{X}&\in\mathbb{R}^{(N+1)\times n_x},\\ \boldsymbol{F}&\in\mathbb{R}^{N\times n_x},\\ \boldsymbol{\Delta}&\in\mathbb{R}^{N\times n_x}. \end{aligned}

The multiplication is therefore conformable.

Composite LGR Quadrature

Let the transformed running cost at each collocation point be

Li(k)=L(Xi(k),Ui(k),ti(k),p).L_i^{(k)} = L\left( \boldsymbol{X}_i^{(k)}, \boldsymbol{U}_i^{(k)}, t_i^{(k)}, \boldsymbol{p} \right).

Stack the values:

L=[L1(1)LN1(1)L1(K)LNK(K)]RN.\boldsymbol{L} = \begin{bmatrix} L_1^{(1)}\\ \vdots\\ L_{N_1}^{(1)}\\ \vdots\\ L_1^{(K)}\\ \vdots\\ L_{N_K}^{(K)} \end{bmatrix} \in\mathbb{R}^N.

The integral is approximated as

11L(s)dsk=1Ki=1Nkwi(k)Li(k).\int_{-1}^{1}L(s)\,\mathrm{d} s \approx \sum_{k=1}^{K} \sum_{i=1}^{N_k} w_i^{(k)}L_i^{(k)}.

Using the stacked vectors:

11L(s)dsWTL.\boxed{ \int_{-1}^{1}L(s)\,\mathrm{d} s \approx \boldsymbol{W}^\mathsf{T}\boldsymbol{L}. }

Discrete Cost Functional

The Bolza objective is

J=Φ(x(t0),t0,x(tf),tf,p)+t0tfL(x,u,t,p)dt.\begin{aligned} J &= \Phi\left( \boldsymbol{x}(t_0),t_0, \boldsymbol{x}(t_f),t_f,\boldsymbol{p} \right) + \int_{t_0}^{t_f} L\left(\boldsymbol{x},\boldsymbol{u},t,\boldsymbol{p}\right)\,\mathrm{d} t. \end{aligned}

The multiple-interval LGR approximation is

Jh=Φ(X1(1),t0,XNK+1(K),tf,p)+tft02WTL.\boxed{ J_h = \Phi\left( \boldsymbol{X}_1^{(1)},t_0, \boldsymbol{X}_{N_K+1}^{(K)},t_f,\boldsymbol{p} \right) + \frac{t_f-t_0}{2} \boldsymbol{W}^\mathsf{T}\boldsymbol{L}. }

This compact expression has exactly the same form as the single-interval LGR objective.

Boundary Constraints

The discrete endpoint constraints are

ϕ(X1(1),t0,XNK+1(K),tf,p)=0.\boxed{ \boldsymbol{\phi}\left( \boldsymbol{X}_1^{(1)},t_0, \boldsymbol{X}_{N_K+1}^{(K)},t_f, \boldsymbol{p} \right) = \boldsymbol{0}. }

Only the first state and final state enter the boundary constraints.

More general bounds may be written as

ϕminϕ(X1(1),t0,XNK+1(K),tf,p)ϕmax.\boldsymbol{\phi}_{\min} \le \boldsymbol{\phi}\left( \boldsymbol{X}_1^{(1)},t_0, \boldsymbol{X}_{N_K+1}^{(K)},t_f,\boldsymbol{p} \right) \le \boldsymbol{\phi}_{\max}.

Path Constraints

Path constraints are evaluated at all collocation points:

cminc(X~,U,S~,t0,tf,p)cmax.\boxed{ \boldsymbol{c}_{\min} \le \boldsymbol{c}\left( \widetilde{\boldsymbol{X}}, \boldsymbol{U}, \widetilde{\boldsymbol{S}}, t_0,t_f,\boldsymbol{p} \right) \le \boldsymbol{c}_{\max}. }

Here:

The final state point is excluded because no control or collocation equation is defined there.

Physical-Time Vector

The global collocation-time vector is

t~=tft02S~+tf+t021N.\widetilde{\boldsymbol{t}} = \frac{t_f-t_0}{2}\widetilde{\boldsymbol{S}} + \frac{t_f+t_0}{2}\boldsymbol{1}_N.

The full state-time vector is

t=tft02S+tf+t021N+1.\boldsymbol{t} = \frac{t_f-t_0}{2}\boldsymbol{S} + \frac{t_f+t_0}{2}\boldsymbol{1}_{N+1}.

If t0t_0 or tft_f is free, every nodal time depends on those decision variables.

Final Nonlinear Programming Problem

The complete multiple-interval LGR transcription is

minX,U,t0,tf,pJh\boxed{ \min_{\boldsymbol{X},\boldsymbol{U},t_0,t_f,\boldsymbol{p}} J_h }

subject to

DXtft02F=0,ϕ(X1,t0,XN+1,tf,p)=0,cminc(X~,U,t~,p)cmax,ZminZZmax.\begin{aligned} \boldsymbol{D}\boldsymbol{X} - \frac{t_f-t_0}{2}\boldsymbol{F} &= \boldsymbol{0}, \\ \boldsymbol{\phi}\left( \boldsymbol{X}_1,t_0, \boldsymbol{X}_{N+1},t_f,\boldsymbol{p} \right) &= \boldsymbol{0}, \\ \boldsymbol{c}_{\min} \le \boldsymbol{c}\left( \widetilde{\boldsymbol{X}}, \boldsymbol{U}, \widetilde{\boldsymbol{t}}, \boldsymbol{p} \right) &\le \boldsymbol{c}_{\max}, \\ \boldsymbol{Z}_{\min} \le \boldsymbol{Z} &\le \boldsymbol{Z}_{\max}. \end{aligned}

A convenient decision vector is

Z=[vec(X)vec(U)t0tfp].\boldsymbol{Z} = \begin{bmatrix} \operatorname{vec}(\boldsymbol{X})\\ \operatorname{vec}(\boldsymbol{U})\\ t_0\\ t_f\\ \boldsymbol{p} \end{bmatrix}.

Equivalence of Global and Multiple-Interval Forms

The single-interval LGR collocation equation is

DsingleX=tft02F.\boldsymbol{D}_{\mathrm{single}}\boldsymbol{X} = \frac{t_f-t_0}{2}\boldsymbol{F}.

The multiple-interval equation is

DmultiX=tft02F.\boldsymbol{D}_{\mathrm{multi}}\boldsymbol{X} = \frac{t_f-t_0}{2}\boldsymbol{F}.

The algebraic form is identical. The difference lies in the structure of D\boldsymbol{D}:

Likewise, the objective retains the form

Jh=Φh+tft02WTL.J_h = \Phi_h + \frac{t_f-t_0}{2} \boldsymbol{W}^\mathsf{T}\boldsymbol{L}.

This structural equivalence simplifies implementation.

Jacobian Sparsity

The global defect constraints are

Δ=DXtft02F(X~,U,t~,p).\boldsymbol{\Delta} = \boldsymbol{D}\boldsymbol{X} - \frac{t_f-t_0}{2} \boldsymbol{F}(\widetilde{\boldsymbol{X}},\boldsymbol{U},\widetilde{\boldsymbol{t}},\boldsymbol{p}).

A defect row in interval kk depends only on:

Therefore, the Jacobian with respect to state and control variables is block sparse.

The principal Jacobian terms are

ΔX=Dtft02FX,\frac{\partial\boldsymbol{\Delta}}{\partial\boldsymbol{X}} = \boldsymbol{D} - \frac{t_f-t_0}{2} \frac{\partial\boldsymbol{F}}{\partial\boldsymbol{X}},

and

ΔU=tft02FU.\frac{\partial\boldsymbol{\Delta}}{\partial\boldsymbol{U}} = - \frac{t_f-t_0}{2} \frac{\partial\boldsymbol{F}}{\partial\boldsymbol{U}}.

Number of Variables and Constraints

Assume:

The state variables contribute

(N+1)nx.(N+1)n_x.

The control variables contribute

Nnu.Nn_u.

Including time and parameters:

nz=(N+1)nx+Nnu+2+np.\boxed{ n_z = (N+1)n_x + Nn_u + 2 + n_p. }

The defect equations contribute

ndefect=Nnx.\boxed{ n_{\mathrm{defect}} = Nn_x. }

Additional constraints arise from endpoint and path conditions.

Implementation Strategy

A robust implementation separates mesh construction from NLP evaluation.

Preprocessing

Before solving:

  1. choose mesh points sks_k;

  2. choose degrees NkN_k;

  3. compute standard LGR nodes and weights;

  4. map nodes into each interval;

  5. scale interval quadrature weights;

  6. scale interval differentiation matrices;

  7. assemble S~\widetilde{\boldsymbol{S}}, S\boldsymbol{S}, W\boldsymbol{W}, and D\boldsymbol{D};

  8. create state and control index maps.

NLP Evaluation

At each NLP iteration:

  1. unpack X\boldsymbol{X}, U\boldsymbol{U}, t0t_0, tft_f, and p\boldsymbol{p};

  2. compute the physical-time vector;

  3. evaluate F\boldsymbol{F} and L\boldsymbol{L};

  4. evaluate the cost;

  5. evaluate defects;

  6. evaluate endpoint constraints;

  7. evaluate path constraints;

  8. evaluate derivatives.

MATLAB Assembly of the Global Matrix

function D = assembleGlobalLGR(Dlocal, degree)

K = numel(degree);
N = sum(degree);

D = sparse(N,N+1);

rowStart = 1;
colStart = 1;

for k = 1:K

    Nk = degree(k);

    rows = rowStart:(rowStart+Nk-1);
    cols = colStart:(colStart+Nk);

    D(rows,cols) = Dlocal{k};

    rowStart = rowStart + Nk;

    % Advance by Nk, not Nk+1, because the last
    % state column is shared with the next interval.
    colStart = colStart + Nk;
end
end

MATLAB Stacking of Nodes and Weights

function [Scol,Sstate,W] = stackLGRData(nodes,weights,mesh)

K = numel(nodes);

Scol = [];
W = [];

for k = 1:K
    Scol = [Scol; nodes{k}(:)];
    W = [W; weights{k}(:)];
end

Sstate = [Scol; mesh(end)];

end

MATLAB Defect Function

function defect = lgrDefect(X,U,t0,tf,Scol,D,p)

N = size(U,1);

t = 0.5*(tf-t0)*Scol ...
  + 0.5*(tf+t0)*ones(N,1);

F = dynamics(X(1:N,:),U,t,p);

defect = D*X - 0.5*(tf-t0)*F;

end

MATLAB Objective Function

function J = lgrObjective(X,U,t0,tf,Scol,W,p)

N = size(U,1);

t = 0.5*(tf-t0)*Scol ...
  + 0.5*(tf+t0)*ones(N,1);

L = runningCost(X(1:N,:),U,t,p);

M = endpointCost(X(1,:),t0,X(end,:),tf,p);

J = M + 0.5*(tf-t0)*(W.'*L);

end

Indexing Example

Suppose

K=3,N1=3,N2=4,N3=2.K=3, \qquad N_1=3, \qquad N_2=4, \qquad N_3=2.

Then

N=3+4+2=9.N=3+4+2=9.

The global state rows are:

1 ⁣: ⁣4for interval 1,4 ⁣: ⁣8for interval 2,8 ⁣: ⁣10for interval 3.\begin{aligned} 1\!:\!4 &\quad\text{for interval 1},\\ 4\!:\!8 &\quad\text{for interval 2},\\ 8\!:\!10 &\quad\text{for interval 3}. \end{aligned}

Rows 4 and 8 are shared interface states.

The global differentiation matrix has size

9×10.9\times10.

The controls have nine rows. The weight vector has nine entries.

Integral State Consistency

The local state update can be checked using LGR quadrature:

XNk+1(k)X1(k)tft02i=1Nkwi(k)Fi(k).\boldsymbol{X}_{N_k+1}^{(k)} - \boldsymbol{X}_1^{(k)} \approx \frac{t_f-t_0}{2} \sum_{i=1}^{N_k} w_i^{(k)} \boldsymbol{F}_i^{(k)}.

For the full horizon:

XN+1X1tft02WTF.\boldsymbol{X}_{N+1} - \boldsymbol{X}_1 \approx \frac{t_f-t_0}{2} \boldsymbol{W}^\mathsf{T}\boldsymbol{F}.

For vector-valued dynamics, the weighted sum is applied columnwise.

This identity is useful for debugging quadrature and indexing.

Why the Final Point Has No Control

The LGR state polynomial requires Nk+1N_k+1 state values, but the dynamics are enforced only at NkN_k LGR points. The additional endpoint is needed to complete the polynomial and represent the terminal state.

Therefore:

state nodes=N+1,control nodes=N.\text{state nodes}=N+1, \qquad \text{control nodes}=N.

A terminal control can be estimated after solving by extrapolation if needed, but it is not an independent NLP variable.

Path-Constraint Verification between Nodes

Enforcing a path constraint only at collocation points does not guarantee that it is satisfied between nodes.

After solving, evaluate the state and control polynomials on a dense grid:

scheck,m[1,1].s_{\mathrm{check},m}\in[-1,1].

Then verify

cminc(xinterp,uinterp,tinterp)cmax.\boldsymbol{c}_{\min} \le \boldsymbol{c}\left( \boldsymbol{x}_{\mathrm{interp}}, \boldsymbol{u}_{\mathrm{interp}}, t_{\mathrm{interp}} \right) \le \boldsymbol{c}_{\max}.

Violations may require:

Motivation for Mesh Refinement

The derivation above assumes that the mesh points and polynomial degrees are given. In practice, the important questions are:

These questions motivate adaptive mesh-refinement algorithms.

hh-, pp-, and hphp-Refinement

hh-Refinement

Decrease interval width by subdividing:

[sk1,sm][sm,sk].\rightarrow [s_{k-1},s_m]\cup[s_m,s_k].

This is suitable near discontinuities or sharp local features.

pp-Refinement

Increase NkN_k while keeping the interval fixed.

This is suitable when the solution is smooth.

hphp-Refinement

Adapt both interval width and polynomial degree.

A practical strategy is:

Error Estimation Concept

Let Xcoll(k)(s)\boldsymbol{X}_{\mathrm{coll}}^{(k)}(s) be the collocation polynomial. Construct an independent state approximation by integrating the dynamics:

Xint(k)(s)=X1(k)+tft02sk1sf(Xcoll(k)(σ),U(k)(σ),t(σ))dσ.\boldsymbol{X}_{\mathrm{int}}^{(k)}(s) = \boldsymbol{X}_1^{(k)} + \frac{t_f-t_0}{2} \int_{s_{k-1}}^s \boldsymbol{f}\left( \boldsymbol{X}_{\mathrm{coll}}^{(k)}(\sigma), \boldsymbol{U}^{(k)}(\sigma), t(\sigma) \right) \,\mathrm{d}\sigma.

Define

ek=maxsSkXint(k)(s)Xcoll(k)(s)1+Xcoll(k)(s).e_k = \max_{s\in\mathcal{S}_k} \frac{ \left\| \boldsymbol{X}_{\mathrm{int}}^{(k)}(s) - \boldsymbol{X}_{\mathrm{coll}}^{(k)}(s) \right\|_\infty }{ 1+\left\|\boldsymbol{X}_{\mathrm{coll}}^{(k)}(s)\right\|_\infty }.

If

ek>ϵ,e_k>\epsilon,

refine interval kk.

Warm Starting after Mesh Refinement

After changing the mesh:

  1. interpolate the previous state solution onto the new state nodes;

  2. interpolate the previous control solution onto the new collocation nodes;

  3. preserve the previous t0t_0, tft_f, and parameters;

  4. project variables onto bounds if necessary;

  5. solve the refined NLP.

Warm starting greatly improves efficiency.

Numerical Conditioning

Potential sources of poor conditioning include:

A practical implementation should scale variables and avoid excessive polynomial degrees within a single interval.

Verification Checklist

A multiple-interval LGR solution should be checked using:

  1. defect residuals;

  2. endpoint residuals;

  3. path constraints at and between nodes;

  4. mesh-refinement convergence;

  5. objective convergence;

  6. independent forward integration;

  7. state continuity at interfaces;

  8. control behavior near switches;

  9. consistency of matrix dimensions;

  10. sensitivity to the initial mesh.

Common Implementation Errors

Summary

The main results of this section are:

  1. The total number of LGR collocation points is

N=k=1KNk.N=\sum_{k=1}^{K}N_k.
  1. There are N+1N+1 unique state nodes and NN control nodes.

  2. Adjacent intervals share one state variable at each mesh point.

  3. The forward LGR control has one value at each interior mesh point.

  4. The global weight vector is obtained by stacking local weights.

  5. The global differentiation matrix has size

N×(N+1).N\times(N+1).
  1. Adjacent local differentiation blocks overlap by one state column.

  2. The global defect equation is

DXtft02F=0.\boldsymbol{D}\boldsymbol{X} - \frac{t_f-t_0}{2}\boldsymbol{F} = \boldsymbol{0}.
  1. The discrete objective is

Jh=Φh+tft02WTL.J_h = \Phi_h + \frac{t_f-t_0}{2}\boldsymbol{W}^\mathsf{T}\boldsymbol{L}.
  1. The multiple-interval and single-interval methods have the same compact algebraic form.

  2. Their principal difference is the sparse structure of the differentiation matrix.

  3. Mesh refinement determines where intervals and polynomial degrees should be placed.

Connection. Once the global method is available, interpolation and integration error estimates can drive an adaptive choice between mesh subdivision and polynomial enrichment.