# Waves through a lens What a lens adds to a wave that comes in from the left: almost nothing in front of it, and a beam behind it. ```python import sympy as sp import pdemagic as pm x, y = sp.symbols("x y", real=True) w = sp.Function("w")(x, y) k = 6 denser = sp.exp(-(x**2 + y**2) / 3) / 2 # n² − 1 incoming = sp.exp(sp.I * k * x) lens = pm.Problem( sp.Eq(pm.laplacian(w) + k**2 * (1 + denser) * w, -(k**2) * denser * incoming), domain=pm.FreeSpace(x, y), ) pm.solve(lens).plot(part="real") ``` ## What it shows The Helmholtz equation in a medium, $\nabla^2 u + k^2 n^2 u = 0$. The index of refraction $n$ is larger where waves travel more slowly, and the lens is a round region in which $n^2$ rises smoothly from 1 to 1.5. A wave that comes in from far away is not a source inside a box, so it is split off: the unknown $w$ is what the lens adds to the incoming wave $e^{ikx}$, and the incoming wave becomes its source. The picture shows that addition: the lens sends hardly anything back, and behind it the added wave forms a beam along the axis. In that beam the whole wave, incoming and added, is up to 2.1 times as strong as it came in. ## What pdemagic decided A coefficient that varies makes this an equation that is solved by an iteration on the solver for constant coefficients (`fourier_iterative`), here in 16 steps. Away from the lens the equation is a Helmholtz equation with the wavelength 1.05. The planner left two wavelengths of room around the lens and gave every wavelength at least six points where the waves are shortest: 192 by 192 points. ## More - [Waves of one frequency](../topics/helmholtz.md) - [Media and potentials: coefficients that vary](../topics/varying.md) - [Equations whose coefficients vary in space](../methods/varying-coefficients.md) - [What is solved in free space and on periodic boxes](../ref/equations-free-space.md)