This page trains a Physics-Informed Neural Network in your browser to solve the 1D viscous Burgers equation, the canonical benchmark from Raissi et al. (2019). No data labels, no ground truth: the network learns purely from the PDE residual, boundary and initial conditions. Hit a preset and watch it converge.
A standard neural network learns from input/output pairs. A PINN learns from a differential equation. Instead of asking "what's the right answer for this input?" it asks "how badly does my prediction violate the laws of physics?", and uses that violation as the loss.
We build a network uθ(t, x) that maps a point in spacetime to a solution value, use automatic differentiation to get its partial derivatives, exactly, not numerically, and plug them into the PDE residual:
A perfect solution has r = 0 everywhere, so the loss is the mean squared residual at random collocation points, plus penalties for the initial and boundary conditions:
No training data is required: the "supervision" is the physics itself. That makes PINNs valuable for inverse problems, high-dimensional PDEs where meshes explode, and domains where the governing equations are known but measurements are scarce, like cardiac biomechanics, my MSc research area.
· Hit 🌊 shock wave and watch a discontinuity form near t ≈ 0.4.
· Set the PDE weight λ to 0.01, the network only learns the boundaries and ignores the physics.
· Hit 🐜 tiny net: an 8×2 MLP simply can't represent the solution. Underfitting, live.
· Push collocation points to 5000 for cleaner residuals at a higher cost per step.
Fully-connected tanh MLP. First derivatives via tf.grad; the second derivative uxx uses a central difference of ux at x ± ε, since TensorFlow.js can't differentiate through tf.grad like PyTorch's create_graph=True or JAX's jacfwd/jacrev: gradients still flow correctly because each ux is itself a full autodiff result. Adam optimizer, WebGL backend, and the training loop adapts how many steps it runs per frame to keep the page smooth on your device.