ES98E · Course contents

Part A · Lectures 5–8

6. Differential equations as models and constraints

A few observations of a trajectory leave infinitely many curves possible between them. If a differential equation is known, its derivative relation can rule out many of those curves without adding labelled solution values. If the equation is partly unknown, observations may instead teach us its missing terms.

These two uses of a network must be distinguished: representing a solution and representing a vector field. Their training and numerical errors are different.

In this chapter: trial solutions, physics-informed losses, learned dynamics, numerical limitations.

Satisfy what can be satisfied exactly

Consider the initial-value problem u′(x)=f(x,u(x))u'(x)=f(x,u(x)), u(0)=u0u(0)=u_0. A trial solution

uw(x)=u0+xgw(x)u_w(x)=u_0+xg_w(x)

enforces the initial value for every parameter vector. Its derivative is gw(x)+xgw′(x)g_w(x)+xg_w'(x). This is the hard-condition trial construction used by Lagaris, Likas and Fotiadis. Choose collocation points x1,…,xNcx_1,\ldots,x_{N_c} and minimise

LR(w)=1Nc∑j=1Nc[uw′(xj)−f(xj,uw(xj))]2.L_R(w)=\frac1{N_c}\sum_{j=1}^{N_c} \left[u_w'(x_j)-f(x_j,u_w(x_j))\right]^2.

Automatic differentiation computes derivatives of the represented computational graph by the chain rule. It avoids finite-difference truncation of that derivative, but remains subject to floating-point error, activation regularity and approximation error in uwu_w. It does not compute the unknown exact solution's derivative “exactly”.

The source's example is

u′=e−x/5cos⁡x−u/5,u(0)=0,u∗(x)=e−x/5sin⁡x.u'=e^{-x/5}\cos x-u/5,\qquad u(0)=0, \qquad u_*(x)=e^{-x/5}\sin x.

Differentiating u∗u_* verifies both the ODE and the initial value. It also supplies a reference against which a trained approximation could be checked. The original numerical fit and extrapolation are not reproducible from the supplied material.

Boundary conditions can similarly be built into a trial function. For u(a)=Au(a)=A, u(b)=Bu(b)=B, use the affine interpolant plus (x−a)(b−x)gw(x)(x-a)(b-x)g_w(x). Hard enforcement removes those boundary penalties, though the ansatz can affect conditioning and expressiveness near the endpoints. A second-order strong-form PDE requires sufficiently differentiable trial functions; piecewise-linear ReLU is not a neutral choice for such residuals.

A residual becomes a training signal

For Nκ[u](x)=s(x)\mathcal N_\kappa[u](x)=s(x), with optional unknown physical parameters κ\kappa, define Rw,κ(x)=Nκ[uw](x)−s(x)R_{w,\kappa}(x)=\mathcal N_\kappa[u_w](x)-s(x). A physics-informed neural network (PINN) combines observations, residuals and boundary/initial information:

L=1Nd∑i∣uw(xi)−yi∣2+λR1Nc∑j∣Rw,κ(ξj)∣2+λBLBC/IC.L=\frac1{N_d}\sum_i|u_w(x_i)-y_i|^2 +\lambda_R\frac1{N_c}\sum_j|R_{w,\kappa}(\xi_j)|^2 +\lambda_B L_{\rm BC/IC}.

If no labelled data are present, omit the first term. If boundary conditions are built in, omit the corresponding penalty. Nondimensionalisation and weighting matter because these terms can have different units and magnitudes. Physics supplies information where labels are scarce; it is a soft constraint unless enforced by construction. This residual-based formulation is developed in Raissi, Perdikaris and Karniadakis.

There is a precise sense in which a residual can control a solution error, but the differential equation's stability supplies the missing step. For the scalar example above, set e=uw−u∗e=u_w-u_* and r=uw′+uw/5−e−x/5cos⁡xr=u_w'+u_w/5-e^{-x/5}\cos x. If the initial value is exact, then

e′+e/5=r,e(x)=∫0xe−(x−t)/5r(t) dt.e'+e/5=r,\qquad e(x)=\int_0^x e^{-(x-t)/5}r(t)\,dt.

Thus for x≥0x\ge0, ∣r(t)∣≤ϵ|r(t)|\le\epsilon throughout [0,x][0,x] implies ∣e(x)∣≤5ϵ(1−e−x/5)|e(x)|\le5\epsilon(1-e^{-x/5}). A small residual everywhere gives a useful bound for this stable ODE. Small residuals at finitely many collocation points do not establish that hypothesis.

Inspect a perturbed trial uw=u∗+0.05sin⁡(6x)u_w=u_*+0.05\sin(6x) alongside its residual. A visibly small displacement can produce a much larger derivative error.

Solution error and equation error differ
Exact solution and perturbed trialux06-0.61dashed: exact · solid: trialResidual of the trial (different y scale)rx06-0.350.35
An analytic illustration, not a trained PINN. The trial adds 0.05 sin(6x) to the exact solution. Its residual is 0.3 cos(6x) + 0.01 sin(6x). The two plots have explicitly different vertical scales; both use x in [0,6]. The trial satisfies u(0) = 0 exactly. ↗

We can make the fitting process inspectable by keeping only the oscillation amplitude unknown. The following animation performs actual gradient steps on that one coefficient. Watch the trial curve and residual change together, then alter the collocation design. The network has been replaced by a transparent analytic family so every update can be checked.

Watch an equation residual guide a fit

uₐ(x) = exp(−x/5) sin x + a sin(6x)

061.1-0.6xtrial and exact solution061-1xresidual (different vertical scale)

amplitude a = 0.150000collocation loss = 4.56e-1

Optimise the single amplitude a using gradient descent on the mean squared residual at equally spaced collocation points. The initial value stays exact. The upper curve compares trial and exact solution; the lower plot shows the continuous residual on a separate vertical scale. This deliberately transparent one-parameter fit is not neural-network training, and sampled loss alone is not a global error certificate. ↗

For inverse problems, optimise ww and κ\kappa together. Sparse observations plus physics can be useful, but parameter identifiability is still necessary: different coefficients and solutions may explain the same measurements. Residual minimisation does not manufacture information absent from the experiment.

Learning the law of motion

A neural ODE instead parameterises

dhdt=gθ(t,h),h(0)=h0,\frac{dh}{dt}=g_\theta(t,h),\qquad h(0)=h_0,

and computes the trajectory with a numerical ODE solver. Parameters are fitted through observed states, differentiating through the solver or using sensitivity/adjoint equations. Smoothness and local Lipschitz conditions support the usual existence and uniqueness theory; solver tolerances and stiffness affect accuracy and cost. The neural ODE construction connects this model to depth-scaled residual networks: an Euler discretisation gives hk+1=hk+Δt gθ(tk,hk)h_{k+1}=h_k+\Delta t\,g_\theta(t_k,h_k).

A vector field also makes the solver error visible. The next example uses a known damped rotation, so its exact trajectory provides a reference for explicit Euler. Its second coordinate is the damped sinusoid from our scalar example. The field stays fixed as the numerical step changes. This is the same distinction that matters when a learned vector field sits inside an ODE solver.

A vector field becomes a trajectory

ẋ = −0.2x − y · ẏ = x − 0.2y

-1.61.61.6-1.6state xstate y (equal units)solid: exact · outlined: Euler

time = 0.00trajectory error = 0.0000

The solid teal particle follows the exact damped rotation. The outlined amber particle follows explicit Euler steps through the same vector field. Changing Δt changes the numerical solver, not the underlying dynamics. Exact radius is exp(−0.2t). Euler is stable only for Δt < 0.4/1.04; divergent paths are clipped at the fixed viewing boundary and reported. ↗

A network that represents one solution is different from a reusable vector field. Once the latter is learned, it can be integrated from other initial states, but reliable transfer depends on whether those states and trajectories lie in a supported regime. For a PINN trained on one boundary-value problem, changing the boundary values usually requires retraining unless they were included as conditioning inputs. Neural operators learn maps from input functions or conditions to solution functions; that is an additional modelling task, not an automatic property of a PINN.

A numerical method still needs an error argument

PINNs can combine sparse data, unknown coefficients and physical constraints using freely placed collocation points. Once trained, evaluating a solution network can be cheap. “Mesh-free” does not mean sampling-free, and training may cost much more than a classical solve. Neural ODE inference still requires integration, with potentially many network evaluations.

Residual losses can be badly conditioned, different loss terms can compete, and sharp features or stiff time scales can be difficult to resolve. In time-dependent problems, global training may fail to learn early-time dynamics adequately; merely sorting the same collocation points does not repair this. A small empirical loss provides neither exact conservation nor a general PDE error bound. Stability, boundary accuracy and residual control between points must be checked.

Finite differences, finite elements and established ODE integrators remain strong choices for well-specified equations, with mature convergence theory and adaptive error control. Networks are especially interesting when representation learning, incomplete physics or repeated parameterised predictions justify their cost. We should compare total accuracy and computation for the intended problem, rather than declare one family universally superior.

So far, observations have supervised a prediction or constrained a physical solution. The next chapter asks what can be learned from unlabelled data alone.