# Bending light in a prescribed gradient

Run `python generate.py` with matplotlib to reproduce the original PNG/SVG/PDF figure, 603 ray rows, six numerical convergence rows and 61 optional temperature-index rows. All index gradients and reference parameters are hypothetical. No measured medium or functioning optical device is represented.

The medium is assigned n(y)=n0+g*y, with n0=1.00027 and transverse gradient g=−0.002, 0 or +0.002 per metre. A ray enters at y=0 with zero transverse slope. Under a small-angle, small-index-variation approximation, y''=g/n0. The reference curve y=g*x²/(2*n0) and slope=g*x/n0 solve this approximate equation analytically. They are not exact solutions of the full ray equation. At x=2 m and positive gradient the displacement is approximately 3.9989 mm and slope approximately 0.0039989. Slope is dy/dx, not an angle in degrees; its numerical value approximates radians only at small angles. The figure exaggerates transverse scale.

The full ray equation in a medium depending only on y can be written y''=(n_y/n)*(1+y'^2). Replacing n by n0 and neglecting y'^2 produces the equation used here. The plotted small slopes and small changes of index make this a controlled teaching approximation; this study does not independently quantify the full-equation discrepancy. Rays turn toward increasing index. A zero gradient leaves the ray straight; reversing the gradient reverses displacement.

An independent explicit Euler integration advances y by slope*dx, then slope by (g/n0)*dx. With 10, 20, 40, 80, 160 and 320 steps, endpoint-position error halves on each refinement as expected for this first-order method. This is numerical error relative to the approximate analytic reference, not uncertainty in a real optical system. Finite differences of the analytic samples reproduce acceleration to maximum absolute error 1.03e-14 per metre. Positive refractive index, monotonic temperature-index relation, sign symmetry and the zero-gradient case are checked.

The separate optional temperature table uses n(T)−1=0.00027*293/T at fixed pressure, gas composition and optical wavelength, assuming weak refractivity proportional to ideal-gas density. It spans 273–333 K and returns n=1.00027 at 293 K. The reference is illustrative rather than a calibrated atmospheric formula. It supplies no spatial temperature profile and is not used to create the ray curves. It cannot predict turbulence, thermal diffusion, gas-flow stability, heating power or control performance.

Established applications of the underlying principle include gradient-index optics and interpretation of bending in nonuniform media. A future engineering study would require measured index maps, wave-optical resolution, boundaries and validated dynamics. This example demonstrates neither a gas lens nor any proposed method of imposing a gradient. Numerical convergence cannot establish physical feasibility.
