Skip to content

How do you tell whether a computed solitary wave follows the KdV equation accurately? In this laboratory you compare a numerical trajectory with an exact pulse, refine time, space and domain separately, and measure conserved integrals. The most revealing result is a failure: a poorly resolved pulse can conserve several integrals almost perfectly.

Required background. Use the KdV travelling wave and the three conserved integrals. You need elementary Python to run or change the experiment. The Fourier convention and time update are developed below.

The exact real-line solution of

ut+6uux+uxxx=0u_t+6uu_x+u_{xxx}=0

is

u∗(x,t)=2κ2sech⁡2 ⁣[κ(x−4κ2t−x0)],κ>0.u_*(x,t)=2\kappa^2\operatorname{sech}^2 \!\left[\kappa(x-4\kappa^2t-x_0)\right], \qquad \kappa\gt0.

Set κ=1\kappa=1, x0=−2x_0=-2 and 0≤t≤10\leq t\leq1. The pulse moves from −2-2 to 22, keeps height 22, and has inverse width 11. The model fixes the zero-background, rapidly decaying regime.

Our computer instead represents a periodic function on [−ℓ/2,ℓ/2)[-\ell/2,\ell/2). Sample at xj=−ℓ/2+jΔxx_j=-\ell/2+j\Delta x, Δx=ℓ/N\Delta x=\ell/N, and impose periodicity through a Fourier series. A restricted line pulse does not satisfy exact periodic matching at the endpoints. Making the box longer reduces this mismatch, but does not turn the torus into the real line. The domain study tests its effect during this finite interval.

If an approximate profile is uh=1.01u∗u_h=1.01u_* at every grid point, what are its relative L2L^2 and maximum errors? What if uh(x)=u∗(x−0.1)u_h(x)=u_*(x-0.1) instead?

Solution and preparation

Both relative errors are 0.010.01 for the uniform amplitude change. The shifted profile needs a pointwise comparison; equal heights do not imply equal functions. To first order, its difference is −0.1 u∗′(x)-0.1\,u_*'(x). This is why the experiment compares profiles before aligning their centers: alignment would hide the phase error we want to measure.

Fourier differentiation and quadratic aliasing

Section titled “Fourier differentiation and quadratic aliasing”

Use Fourier modes eikmxe^{ik_mx}, km=2πm/ℓk_m=2\pi m/\ell. Differentiation multiplies a coefficient by ikmik_m. Since (ikm)3=−ikm3(ik_m)^3=-ik_m^3, the Fourier evolution has the sign

v˙m=ikm3vm+Gm(v),Gm(v)=−3ikmu2^m.\dot v_m=ik_m^3v_m+G_m(v),\qquad G_m(v)=-3ik_m\widehat{u^2}_m.

The factor 33 comes from 6uux=3(u2)x6uu_x=3(u^2)_x. NumPy’s forward FFT has no 1/N1/N factor; its inverse supplies that factor. The code uses this pair consistently.

Multiplying sampled functions can wrap high frequencies into low ones. To prevent that error for the quadratic term, retain only integer modes satisfying ∣m∣<N/3|m|\lt N/3, project the initial field, and apply the same projection after every nonlinear evaluation. If two retained modes sum outside the retained band, their wrapped sum cannot fall back inside it. The strict inequality removes the borderline case. This is the 2/3 dealiasing rule.

Thus N=512N=512 grid points retain 341 Fourier modes. Dealiasing makes the retained quadratic convolution correct; it cannot recover an unresolved narrow pulse. The experiment independently compares the FFT product with an explicit non-circular convolution on a small random Fourier polynomial.

Integrate dispersion exactly within each time step

Section titled “Integrate dispersion exactly within each time step”

Write the finite Fourier system as v′=Dv+G(v)v'=Dv+G(v), with Dm=ikm3D_m=ik_m^3. On one step, introduce the local variable

w(s)=e−sDv(t+s),w′(s)=e−sDG ⁣(esDw(s)),0≤s≤h.w(s)=e^{-sD}v(t+s),\qquad w'(s)=e^{-sD}G\!\left(e^{sD}w(s)\right), \quad 0\leq s\leq h.

Apply ordinary fourth-order Runge–Kutta to this equation and restore v(t+h)=ehDw(h)v(t+h)=e^{hD}w(h). The linear dispersive phase is exact, while the nonlinear evolution still has time error. This is integrating-factor RK4, as described by Kassam and Trefethen 2005, pp. 1215–1216, equations (1.5)–(1.9), PDF. It is distinct from their ETDRK4 method.

For the diagonal multiplier E=ehD/2\mathcal E=e^{hD/2}, the implemented stages are

a=G(v),b=G ⁣(E(v+ha/2)),c=G ⁣(Ev+hb/2),d=G ⁣(E2v+hEc),vnew=E2v+h6[E2a+2E(b+c)+d].\begin{aligned} a&=G(v),\\ b&=G\!\left(\mathcal E(v+ha/2)\right),\\ c&=G\!\left(\mathcal Ev+hb/2\right),\\ d&=G\!\left(\mathcal E^2v+h\mathcal Ec\right),\\ v_{\mathrm{new}}&=\mathcal E^2v+\frac h6 \left[\mathcal E^2a+2\mathcal E(b+c)+d\right]. \end{aligned}

The code checks these stages against a separate implementation of RK4 in ww. It also sets G=0G=0 and checks the exact Airy wave cos⁡(kx+k3t)\cos(kx+k^3t), catching a reversed dispersive sign. Removing linear stiffness does not make arbitrarily large nonlinear steps reliable.

Download and extract the complete KdV experiment (ZIP), then open its kdv folder. Individual files are also available: experiment.py, inputs.json, results.json, requirements.txt, and computation notes. The recorded run used Python 3.9.6, NumPy 2.0.2 and binary64 arithmetic. With Python 3.9–3.12, run in that folder:

Terminal window
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python experiment.py --check

On Windows the virtual-environment executable is .venv\Scripts\python.exe. In an existing checkout with NumPy installed, run python3 public/computations/kdv/experiment.py --check. The check recomputes all studies without changing files. Running without a flag prints fresh results; --write deliberately regenerates the saved JSON. Modify a separate working copy when exploring new inputs.

For grid samples ej=uj−u∗(xj,T)e_j=u_j-u_*(x_j,T), report

ϵ2=(Δx∑j∣ej∣2)1/2(Δx∑j∣u∗(xj,T)∣2)1/2,ϵ∞=max⁡j∣ej∣max⁡j∣u∗(xj,T)∣.\begin{aligned} \epsilon_2&= \frac{\left(\Delta x\sum_j|e_j|^2\right)^{1/2}} {\left(\Delta x\sum_j|u_*(x_j,T)|^2\right)^{1/2}},\\ \epsilon_\infty&= \frac{\max_j|e_j|}{\max_j|u_*(x_j,T)|}. \end{aligned}

These are normalized discrete approximations to the two norms, at T=1T=1. They include projection, evolution and finite-domain discrepancies. The profiles are not shifted to improve their agreement.

Hold ℓ=48\ell=48 and N=512N=512 fixed.

Time step hhϵ2\epsilon_2ϵ∞\epsilon_\infty
1/1601/1605.65×10−55.65\times10^{-5}4.50×10−54.50\times10^{-5}
1/3201/3202.50×10−62.50\times10^{-6}2.38×10−62.38\times10^{-6}
1/6401/6401.33×10−71.33\times10^{-7}1.22×10−71.22\times10^{-7}
1/12801/12807.42×10−97.42\times10^{-9}7.50×10−97.50\times10^{-9}

The successive estimates log⁡2[ϵ2(h)/ϵ2(h/2)]\log_2[\epsilon_2(h)/\epsilon_2(h/2)] are 4.504.50, 4.234.23 and 4.164.16, approaching the method’s fourth order. These measurements apply to the tested smooth pulse and resolutions; they are not a universal stability guarantee.

Now hold ℓ=48\ell=48 and h=1/3200h=1/3200 fixed. Monitor

M=∫u dx,P=∫u2 dx,E=∫(u3−12ux2)dx.M=\int u\,dx,\qquad P=\int u^2\,dx,\qquad E=\int\left(u^3-\frac12u_x^2\right)dx.

For the exact line pulse these are 4κ4\kappa, 16κ3/316\kappa^3/3 and 32κ5/532\kappa^5/5. The model’s translation generator and Hamiltonian are P/2P/2 and H=−EH=-E. The code records maximum drift from each initial discrete value over all time steps, divided by its exact line value; it also records the initial line-integral error separately.

Grid points NNϵ2\epsilon_2ϵ∞\epsilon_\inftyLarger normalized drift of P,EP,E
641.62×10−11.62\times10^{-1}1.56×10−11.56\times10^{-1}1.65×10−131.65\times10^{-13}
961.98×10−21.98\times10^{-2}1.70×10−21.70\times10^{-2}1.35×10−121.35\times10^{-12}
1281.81×10−31.81\times10^{-3}1.84×10−31.84\times10^{-3}5.66×10−125.66\times10^{-12}
1923.20×10−53.20\times10^{-5}2.67×10−52.67\times10^{-5}1.29×10−111.29\times10^{-11}
2564.61×10−74.61\times10^{-7}3.50×10−73.50\times10^{-7}1.39×10−111.39\times10^{-11}
3842.17×10−102.17\times10^{-10}2.40×10−102.40\times10^{-10}1.39×10−111.39\times10^{-11}

At N=64N=64, the profile error is about 16%16\% even though the conserved quantities barely drift. The truncated Fourier dynamics can preserve its integrals while representing the continuum pulse poorly. In the following figure, compare the separation of the solid and dashed curves at the coarsest grid.

Spatial refinement reduces the relative pulse error from about sixteen percent to two times ten to the minus ten, while the conserved-integral drift stays tiny even on the inaccurate coarse grid.

Small invariant drift does not imply an accurate KdV profile. These quantitative curves use the table above, with κ=1\kappa=1, x0=−2x_0=-2, T=1T=1, ℓ=48\ell=48 and h=1/3200h=1/3200. The dashed curve is the larger normalized drift of PP and EE over the sampled time steps. The vertical axis is logarithmic; the lines only connect tested resolutions.

Finally hold Δx=1/8\Delta x=1/8 and h=1/3200h=1/3200 fixed, increasing NN with ℓ\ell.

Period length ℓ\ellGrid points NNϵ2\epsilon_2ϵ∞\epsilon_\infty
161281.37×10−51.37\times10^{-5}2.33×10−52.33\times10^{-5}
241924.73×10−94.73\times10^{-9}7.81×10−97.81\times10^{-9}
322562.08×10−102.08\times10^{-10}2.35×10−102.35\times10^{-10}
483842.17×10−102.17\times10^{-10}2.40×10−102.40\times10^{-10}

The initial/final endpoint values, as fractions of the pulse height, fall from 2.46×10−52.46\times10^{-5} at ℓ=16\ell=16 to 3.11×10−193.11\times10^{-19} at ℓ=48\ell=48. The last two errors form a floor set by remaining time and spatial errors. Their small difference does not establish that the smaller box is more accurate in general. Holding NN fixed while enlarging the box would coarsen Δx\Delta x and mix two effects.

The separate reference run at ℓ=48\ell=48, N=512N=512 and h=1/3200h=1/3200 has ϵ2=1.80×10−10\epsilon_2=1.80\times10^{-10} and ϵ∞=1.87×10−10\epsilon_\infty=1.87\times10^{-10}. Its largest normalized integral drift is 1.39×10−111.39\times10^{-11}.

A false solution with perfect line integrals

Section titled “A false solution with perfect line integrals”

Translate the correct shape at half the correct speed:

uwrong(x,t)=2κ2sech⁡2 ⁣[κ(x−2κ2t−x0)].u_{\mathrm{wrong}}(x,t)=2\kappa^2 \operatorname{sech}^2\!\left[\kappa(x-2\kappa^2t-x_0)\right].

Translation leaves M,P,EM,P,E unchanged, yet substitution gives

(ut+6uux+uxxx)wrong=2κ2(uwrong)x,(u_t+6uu_x+u_{xxx})_{\mathrm{wrong}} =2\kappa^2(u_{\mathrm{wrong}})_x,

which is nonzero. At T=1T=1, its relative L2L^2 error is 1.231.23, while the three sampled integrals differ from the exact line values by at most 1.4×10−161.4\times10^{-16} relative. This deliberately incorrect trajectory shows why an equation residual or independent solution comparison is indispensable.

Using the last two temporal L2L^2 errors, compute the observed order and predict the error after one more halving if fourth-order behavior dominates. State one reason the prediction can fail.

Hint

Divide the errors, take the base-two logarithm, then use a factor of 242^4 for the prediction.

Solution

The ratio is about 17.917.9, giving order 4.164.16. Fourth-order scaling predicts 7.42×10−9/16≈4.64×10−107.42\times10^{-9}/16\approx4.64\times10^{-10}. A remaining spatial, domain or roundoff error can spoil this scaling; the coefficient can also change before the asymptotic regime is reached. An observed order is evidence about this refinement, not an exact law for every step size.

Independent: expose the conservation blind spot

Section titled “Independent: expose the conservation blind spot”

Use the N=64N=64 spatial result to assess the claim: “The pulse is accurate to twelve digits because its conserved quantities drift by less than 10−1210^{-12}.” Distinguish the initial projection, the finite Fourier evolution and the continuum solution.

Hint

Inspect the profile error and the separate initial-projection fields in the saved JSON. Conservation measures change along a trajectory, not its distance from the requested trajectory.

Solution

The claim is false: the final profile has relative L2L^2 error about 0.1620.162. Projection discards high Fourier modes before time stepping. The retained system then evolves different finite-dimensional data and can nearly preserve its own discrete integrals. Neither that preservation nor agreement of a few initial integrals bounds the full field error. The spatial-refinement comparison directly tests the lost-resolution effect.

Change κ\kappa from 11 to 22. How should spatial resolution, time interval and time step scale to compare the same dimensionless motion? Explain why doubling NN alone is insufficient.

Hint

Use X=κxX=\kappa x, τ=κ3t\tau=\kappa^3t and u=κ2Uu=\kappa^2U.

Solution

To keep the scaled grid and motion fixed, halve Δx\Delta x, divide TT and hh by eight, and halve the period length and initial center when scaling the whole physical setup. Equivalently, on an unchanged large box one needs at least twice as many points to keep the same points per width, while still refining time for the eightfold nonlinear/dispersive time scale. Doubling NN alone leaves the temporal and domain comparisons uncontrolled. Run new separate refinements; the saved acceptance results cover the original parameter set.

  • Kassam, Aly-Khan, and Lloyd N. Trefethen. “Fourth-order time-stepping for stiff PDEs.” SIAM Journal on Scientific Computing 26(4), 1214–1233 (2005). DOI. Open PDF.