# A string on a bed that hardens A pulse runs along a string whose bed hardens where the string has moved, at five times. ```python import sympy as sp import pdemagic as pm x, t = sp.symbols("x t", real=True) u = sp.Function("u")(x, t) w = sp.Function("w")(x, t) pulse = sp.exp(-((x - 8) ** 2) / 2) string = pm.Problem( sp.Eq(u.diff(t, 2), u.diff(x, 2) - w * u / 2), sp.Eq(w.diff(t), w.diff(x, 2) / 10 + u**2), domain=pm.Box({x: (0, 40)}), time=(t, 0, 24), initial={u: pulse, u.diff(t): -pulse.diff(x), w: 0}, boundary=[sp.Eq(u, 0), sp.Eq(w.diff(x), 0)], ) plan = pm.plan(string) plan.method.tolerance = 1e-6 pm.solve(string, plan).plot(unknown=u) ``` ## What it shows A string lies on a bed that pulls it back to rest, with a stiffness $w$ that is zero at the start. Where the string is deflected the bed warms and hardens, at the rate $u^2$, and the warmth spreads slowly along it. A pulse starts at $x = 8$ and runs to the right with the speed 1. On a soft bed it would keep its shape. This one hardens the bed under itself as it passes, and the hardened bed changes it: its front still runs at the speed 1, but behind the front a train of waves forms, shorter towards the front, and a part of the pulse is thrown back and stays behind as a slow swell. The two equations are of different kinds. The string obeys an equation of second order in time, a wave equation, and the stiffness one of first order, a diffusion. Each acts on the other through a term without a derivative. ## What pdemagic decided A wave and a diffusion between walls are stepped together (`exponential_runge_kutta`). Each unknown is expanded in its own modes of the box, $u$ with the ends held and $w$ with the ends closed. The wave equation is exact, for $u$ and its rate of change together, and so is the diffusion of $w$. The two terms that couple them are stepped. The grid has 256 Chebyshev points. The example loosens the tolerance of a step to $10^{-6}$, which is plenty for a picture and takes 80 steps where the planner's $10^{-10}$ takes 640. The diagnostic `solution_tail` is $5\cdot10^{-6}$ at the end: the waves behind the front are the finest thing in the picture, and a finer grid would resolve them further. ## More - [Systems of equations](../topics/systems.md) - [Nonlinear equations in time](../topics/nonlinear-time.md) - [Systems between walls, the method](../methods/systems-between-walls.md) - [What is solved on boxes with walls](../ref/equations-boxes.md)