Fundamentals / Numerical mathematics / Numerical ordinary differential equations

Differential–algebraic equations and consistency

Derive a reduced evolution when an algebraic variable can be eliminated and find the hidden velocity constraint in a mechanical example.

From first principles

Determine which initial states can satisfy an algebraic constraint

A differential–algebraic model may evolve \(y\) while determining \(z\) instantaneously through a constraint. In a semi-explicit model, \(y'=f(t,y,z)\) specifies a rate and \(g(t,y,z)=0\) specifies admissible states. Initial data must satisfy the latter before the first time step. A differentiable solution must remain on it, hence the time derivative along the trajectory vanishes:

\[0=\frac{d}{dt}g(t,y,z)=g_t+g_y f+g_z\dot z .\]

If the square matrix \(g_z\) is invertible near the initial state, the constraint locally determines \(z\) from \(t,y\), and the hidden rate is

\[\dot z=-g_z^{-1}(g_t+g_y f).\]

For example impose the unit circle \(y^2+z^2=1\) with \(y'=u(t)\). On its upper half \(z=\sqrt{1-y^2}\), giving \(\dot z=-yu/z\). Algebraic consistency fixes \(z(0)\) once the branch and \(y(0)\) are known. At \(z=0\) this coordinate elimination becomes singular even though the circle itself is smooth. A constrained implicit time step imposes the original algebraic equation at the new time, which prevents the numerical drift that can accumulate from integrating only its differentiated version.

Derivation and applications

Derive the constraint force of a pendulum without eliminating coordinates

A solver using Cartesian coordinates for a pendulum must satisfy geometric, velocity and acceleration constraints. Let \(\mathbf r=(x,y)\) be the displacement from a fixed pivot, \(\mathbf v=\dot{\mathbf r}\), \(m\) the bob mass, and \(L\) the fixed link length. The applied force \(\mathbf F\) excludes the constraint reaction. Write the reaction as \(-\lambda\mathbf r\), so positive \(\lambda\) corresponds to an inward force and has units of N/m. The holonomic constraint and its first derivative are

\[g=\tfrac12(\mathbf r\cdot\mathbf r-L^2)=0,\]
\[\dot g=\mathbf r\cdot\mathbf v=0.\]

Differentiating once more shows that the acceleration is generally not tangent: maintaining curvature of the trajectory requires an inward normal component. Insert Newton's law and keep the known tangential speed:

\[\ddot g=|\mathbf v|^2+\mathbf r\cdot\dot{\mathbf v}=0,\]
\[m\dot{\mathbf v}=\mathbf F-\lambda\mathbf r .\]

Solving for the scalar multiplier gives both the required magnitude and the tangentially projected forcing:

\[\lambda=\frac{m|\mathbf v|^2+\mathbf r\cdot\mathbf F}{L^2},\]
\[\dot{\mathbf v}=\frac{\mathbf F}{m}-\frac{\lambda}{m}\mathbf r .\]

The multiplier can be found only after compatible position and velocity are supplied. Satisfying the position constraint alone at the initial time does not remove radial velocity. For a rigid rod either sign of \(\lambda\) is admissible. A string goes slack when the bilateral model would require compression.

Worked example

Calculate a reaction at the bottom of a swing

Choose \(y\) upward, \(m=0.200\) kg, \(L=0.500\) m, \(\mathbf r=(0,-0.500)\) m and \(\mathbf v=(1.00,0)\) m/s. Gravity is \((0,-1.962)\) N. Thus \(\lambda=[0.200+0.981]/0.250=4.724\) N/m, giving tension \(\lambda L=2.36\) N. The net upward acceleration is \((2.362-1.962)/0.200=2.00\) m/s², independently equal to \(v^2/L\).

Second application

Detect an inconsistent input and a physically slack string

At the same bottom position, a supplied velocity \((1.00,0.100)\) m/s has \(\mathbf r\cdot\mathbf v=-0.0500\) m²/s. Removing its radial projection gives \((1.00,0)\) m/s before evaluating the multiplier. At the top, instead take \(\mathbf r=(0,0.500)\) m and tangential speed \(1.00\) m/s. The bilateral equation predicts

\[\lambda L=0.400-1.962=-1.56\,\mathrm{N}.\]

A string cannot provide that outward push, so a taut-string simulation must release the constraint there.

A state has fewer independent coordinates than entries

A semi-explicit system has \(y'=f(t,y,z)\) and \(0=g(t,y,z)\). The algebraic equation supplies a condition at every instant; choosing every initial coordinate independently can violate it before time integration starts. If \(g_z\) is square and nonsingular locally, the implicit function theorem determines \(z=\psi(t,y)\) and substitution gives an ordinary differential equation for \(y\). Differentiating the constraint gives \(g_z z'=-g_t-g_y f\), so one differentiation determines the missing derivative. This is the usual semi-explicit index-one situation.

For \(y'=-y+z,\quad0=y+2z-t\), one has \(z=(t-y)/2\) and \(y'=(t-3y)/2\). If \(y(0)=2\), consistency forces \(z(0)=-1\) and \(y'(0)=-3\). Differentiating the constraint gives

\[z'(0)=(1-y'(0))/2=2.\]

Entering both initial coordinates as zero and two in the wrong order would describe a different trajectory even if a numerical solver silently repaired their algebraic inconsistency.

Discretise both conditions at the same time

A backward Euler step at \(h=0.2\) enforces \(y_1-2=0.2(-y_1+z_1)\) and \(y_1+2z_1=0.2\). Eliminating \(z_1\) gives \(1.3y_1=2.02\), so \(y_1\approx1.553846\) and \(z_1\approx-0.676923\). Computing the second variable from the new time matters. Using \(z_0\) throughout the update and reporting it as the new algebraic variable would violate the current constraint. Report its residual together with the local or global accuracy estimate for \(y\).

Hidden constraints and the force multiplier

For a unit-mass pendulum with Cartesian position \(q\), velocity \(v\), rod length \(L\) and downward gravity vector \(g\), take \(q'=v,\ v'=g-\lambda q\) and \(q^Tq=L^2\). Differentiating the rod constraint once imposes \(q^Tv=0\); velocity must be tangent to the circle. Differentiating again gives \(v^Tv+q^Tg-\lambda L^2=0\), determining the multiplier \(\lambda=(v^Tv+q^Tg)/L^2\). The original position constraint contains no direct multiplier, so the index-one elimination used above does not apply.

At the bottom of a 1 m pendulum take \(q=(0,-1)\) m, \(v=(2,0)\) m/s and \(g=(0,-9.81)\) m/s². The multiplier is \(13.81\) s⁻² and acceleration is \((0,4)\) m/s², the required inward centripetal acceleration. A velocity with a nonzero vertical component would already violate tangency at this position. Advancing differentiated equations alone can let position and tangent constraints drift because rounding and discretisation accumulate. Check both \(q^Tq-L^2\) and \(q^Tv\) over time; projecting position alone may leave a velocity pointing slightly through the rod constraint.

An algebraic residual can hide an inaccurate state

For the linear example, change a consistent state at fixed time by \(\delta y=0.02,\ \delta z=-0.01\). Its constraint residual stays exactly zero, since those changes cancel in \(y+2z\). Its differential right-hand side changes by \(-0.03\). The perturbation lies along the constraint manifold and is invisible to any diagnostic that checks only the algebraic equation. Conversely a perturbation normal to the manifold can be easy to see in the residual even if \(y\) is accurate. Estimate time-discretisation error by a separate comparison, such as refining the time step at a common physical output time.

Project an inconsistent state in a physically weighted metric

Suppose linear constraints require \(Bq=g\), while an unconstrained time step produces \(q^\ast\) with a small violation. A correction can be selected by minimising \((q-q^\ast)^TM(q-q^\ast)/2\) subject to the constraint, with \(M\) symmetric positive definite and \(B\) of full row rank. Stationarity gives

\[M(q-q^\ast)+B^T\lambda=0.\]

Inserting the resulting \(q=q^\ast-M^{-1}B^T\lambda\) into the constraint yields the smaller system \(BM^{-1}B^T\lambda=Bq^\ast-g\). This formula corrects exactly the component normal to the feasible plane in the chosen metric.

If \(M\) is a mass matrix for velocity variables, minimising this norm has a kinetic-energy interpretation. For position variables it is still a chosen distance measure and should be justified by the desired correction. Dependent constraint rows can make the multiplier system singular even when the geometrically projected state is unique. Nonlinear constraints require updating their Jacobian during a projection, and a large correction may find a different feasible branch. Satisfying the algebraic constraint alone does not guarantee a time-accurate differential state.

Position and velocity require two distinct projections

Let \(M=\operatorname{diag}(1,4)\), \(B=(1,1)\) and require \(q_1+q_2=2\). An unconstrained update gives

\[q^\ast=(1.2,1.0)^T,\]

with gap 0.2. The scalar multiplier matrix is \(1+1/4=1.25\), so \(\lambda=0.16\). Since \(M^{-1}B^T=(1,1/4)^T\), the correction is \((-0.16,-0.04)^T\), leaving \(q=(1.04,0.96)^T\). A Euclidean projection would subtract 0.1 from each coordinate. Both restore the same constraint, but the mass-weighted correction moves the heavier coordinate less.

For a constant constraint value, consistent velocities must also satisfy \(Bv=0\). Suppose \(v^\ast=(2,-1)^T\), with violation one. The velocity multiplier is \(1/1.25=0.8\), giving \(v=(1.2,-1.2)^T\). Its kinetic energy is \((1.2^2+4\cdot1.2^2)/2=3.6\), compared with \((2^2+4)/2=4\) before correction. The lost 0.4 is exactly half the squared mass norm of the removed normal component \((0.8,0.2)^T\). Orthogonality eliminates the cross term in this energy decomposition.

This reduction illustrates why projecting velocities can suppress energy even if the underlying unconstrained update had no dissipative force. In a simulation of sustained motion, report correction norms or constraint impulses along with the residual after projection. With a moving constraint \(Bq=g(t)\), the velocity condition becomes \(Bv=g'(t)\), so forced boundary motion can do physical work. Applying a zero-velocity projection to that case would remove a legitimate component of the solution.

For the linear position example the chosen correction is also the smallest in the prescribed metric by direct comparison. Every other feasible correction has the form \((-0.16,-0.04)+t(1,-1)\). Its squared mass norm equals \(0.032+5t^2\) because the mass-weighted cross term vanishes. The Euclidean correction corresponds to \(t=0.06\), giving squared mass norm 0.05 rather than 0.032. This calculation makes the meaning of the multiplier solution visible without invoking a general optimisation theorem. If \(B\) varies with time, differentiating \(B(t)q=g(t)\) also introduces the term \(B'(t)q\) in the velocity condition, even for a constant prescribed value.

The derivative of the constraint must therefore be evaluated at the same time as the corrected velocities.

Change parameters · Explore the worked calculation

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.