Solve the 1D Laplace equation with an iterative solver. Change the relaxation factor omega to see how much faster convergence becomes when the Gauss-Seidel update is amplified to "overshoot", and watch the optimal omega and the residual decay in real time.
Parameters
1D grid points n
Number of interior unknowns (excluding boundaries)
Relaxation factor ω
ω=1 is Gauss-Seidel. ω≥2 diverges
Left boundary value φL
Right boundary value φR
Max iterations
Iteration is stopped if not converged by this count
Results
—
Iterations to converge
—
Relaxation factor ω
—
Optimal ω (theory)
—
Speed-up vs Gauss-Seidel
—
Final residual
—
Converged / diverged
—
Relaxation sweep animation
Starting from a flat initial state, the φ profile relaxes toward the straight-line solution with every SOR sweep. With over-relaxation (ω>1) the profile briefly overshoots before settling.
The SOR update. Each sweep computes the Gauss-Seidel value (φ_{i−1}+φ_{i+1})/2 from the latest neighbour values, then amplifies it by the factor ω. With ω=1 this reduces to the Gauss-Seidel method.
Approximate optimal relaxation factor for the 1D Laplace problem with n interior points. The larger n is, the closer ω_opt is to 2. ω must stay below 2 for stability.
The 1D Laplace equation being solved, together with its discrete equation and exact solution. The exact solution is the straight line joining the two boundary values.
What is the Successive Over-Relaxation (SOR) Simulator?
🙋
I've heard that a CAE analysis ultimately comes down to solving a huge system of equations. Is the SOR method one of those solvers?
🎓
Exactly. Whether it's structures, heat or fluids, discretising a partial differential equation on a grid eventually gives a system of linear equations Ax=b with anywhere from tens of thousands to billions of unknowns. Solving that head-on with elimination blows up both compute and memory, so we use an "iterative solver" that creeps toward the answer step by step. SOR is the flagship of those iterative solvers — and the simplest place to learn the idea of "relaxation".
🙋
"Relaxation" — like easing into something? Getting closer to the answer little by little, right?
🎓
That image is close. What this tool solves is the 1D Laplace equation d²φ/dx²=0, whose answer is just a straight line joining the two boundary values. At every grid point the condition is "my value = the average of my two neighbours". So we loop over all points, replacing φ_i with the neighbour average. That is the Gauss-Seidel method. Sweep many times and a profile that started flat slowly "relaxes" into the straight line. Set ω to 1.0 on the left and watch the animation above.
🙋
I tried it. But at ω=1 it takes quite a few sweeps to reach the line... Does the "over-relaxation" in SOR speed this up?
🎓
Yes, that's the heart of it. A single Gauss-Seidel step only nudges things a little each time. So the idea of SOR — successive over-relaxation — is "if it's going to move that way anyway, let's be bolder" and amplify the update by a factor of ω. In a formula: φ_i ←(1−ω)φ_i + ω×(neighbour average). Set ω to 1.5 or 1.8 and look at the iteration-count card — it should converge in a fraction of the Gauss-Seidel count. The "iterations vs ω" chart below traces a sharp U-shaped valley.
🙋
So the bottom of the valley is fastest. But when I push ω too close to 2, the card suddenly says "diverged". Why?
🎓
There is a limit to overshooting. The higher ω, the "bolder" each step — but once ω≥2 you overshoot so much every sweep that the error, instead of shrinking, gets amplified each iteration. That is divergence. In theory SOR converges only for 0<ω<2, and within that range there is an "optimal ω" that is fastest. In 1D it is ω_opt=2/(1+sin(π/(n+1))). The opposite, ω<1 "under-relaxation", is stable but slower than Gauss-Seidel. So you aim between 1 and 2, and near the bottom of the valley.
🙋
I see. The optimal ω changes with the grid count n. In practice, can I always set ω from this formula?
🎓
Unfortunately the clean ω_opt formula only works for tidy problems like this 1D Laplace case. In real CAE the matrix is complex and the optimal ω is often unknown in advance. Engineers do a few trial solves to estimate ω, or start from an empirical value around ω=1.8. That's exactly why getting a feel for the ω-versus-iteration relationship with a tool like this helps you read the behaviour of the real solver too.
Frequently Asked Questions
The Gauss-Seidel method updates each grid point to the average of its latest neighbour values. SOR (successive over-relaxation) amplifies that update by a relaxation factor omega: phi_i <- (1-omega)phi_i + omega(Gauss-Seidel value). With omega=1 this is exactly Gauss-Seidel, but for 1
For the 1D Laplace equation on a uniform grid of n interior unknowns, the omega that minimises the iteration count is approximated by omega_opt = 2/(1+sin(pi/(n+1))). The finer the grid (larger n), the closer omega_opt is to 2. For n=25, omega_opt is about 1.785. In practice omega_opt falls in the 1.7-1.95 range for many problems. Making omega either smaller or larger than this raises the iteration count, producing a U-shaped curve with a sharp minimum at omega_opt. The 'iterations vs omega' chart in this tool shows that shape.
The necessary condition for SOR to converge is 0=2 the spectral radius of the iteration matrix reaches or exceeds 1, the error is amplified every sweep and the method diverges. The residual grows exponentially instead of shrinking and eventually overflows to infinity. Conversely omega<1 is 'under-relaxation' — it still converges but slower than Gauss-Seidel. Stable and fast means 1=2, or failure to converge within the iteration cap, as diverged.
SOR is a classic iterative solver long used to solve the large sparse systems that arise from discretising elliptic partial differential equations — structural analysis, heat conduction, electromagnetics and fluid flow (especially the pressure Poisson equation). Modern large-scale CAE favours faster methods such as conjugate gradients (CG), multigrid and algebraic-multigrid preconditioned Krylov solvers, but SOR is still active as a smoother (preconditioner) inside those advanced methods. Its simple, easy-to-implement algorithm also makes it an ideal teaching example for the behaviour of iterative solvers — residual decay and the effect of the relaxation factor.
Real-World Applications
Steady-state heat conduction and diffusion: A steady-state temperature field obeys the Laplace equation where there is no heat source (the Poisson equation where there is one). Discretising an electronics heat sink, building insulation or a sub-surface temperature field with FDM/FVM gives exactly the "each value = the average of its surroundings" type of system used by this tool, which SOR can solve. In 1D the solution is a straight line, but the idea carries over to 2D and 3D.
The pressure Poisson equation in fluid analysis: The SIMPLE method and fractional-step methods for incompressible flow must solve a pressure Poisson equation at every time step. Because this dominates the run time, a fast iterative solver is essential. Classic codes used SOR (and its symmetric variant SSOR); modern codes use multigrid or preconditioned conjugate gradients, but SOR is still built in as a smoother that damps high-frequency error.
Electrostatic and magnetostatic field analysis: The Laplace/Poisson equation that the potential satisfies appears in electromagnetic analysis of capacitors, insulation design and motor magnetic circuits. Finding the interior potential distribution from prescribed boundary potentials (Dirichlet conditions) is precisely the structure of this tool, and SOR iteration solves it efficiently.
Teaching and algorithm verification: SOR can be implemented in just a few lines, and the convergence acceleration and divergence caused by the relaxation factor omega are clearly observable, so it is widely used as an introductory exercise in numerical analysis. When implementing a new solver, engineers often first build a "correct solution" and a "convergence baseline" with SOR and use it as the reference for verifying more advanced methods.
Common Misconceptions and Pitfalls
The most common pitfall is assuming "larger omega is always faster". Raising omega increases the update per step, but the iteration count does not fall monotonically. Around the optimal omega (here omega_opt = 2/(1+sin(pi/(n+1)))), making omega either larger or smaller raises the iteration count — which is why the chart traces a sharp U shape. And once omega>=2 the error is amplified and the method diverges. The right move is not "set omega near 2 for top speed" but to aim for the bottom of the valley.
Next, assuming the optimal-omega formula works for any problem. omega_opt = 2/(1+sin(pi/(n+1))) is a theoretical value for the very tidy case of a 1D (or square-domain 2D) Laplace problem on a uniform grid. In real CAE the domain shape is complex, material properties vary with position, convection terms appear, and the spectral radius of the matrix cannot be found analytically. The optimal omega is then unknown in advance — you estimate it with trial solves or start from an empirical value around omega=1.7-1.9. Treat the formula value as a rough guide for tidy problems only.
Finally, SOR is not an all-purpose fast solver. SOR is easy to implement and works well on small problems such as the 1D case, but as the grid count n grows, the iterations needed to converge also grow, and efficiency plateaus for large problems. Even with the optimal omega it still cannot match multigrid or preconditioned conjugate gradients in convergence speed. SOR rarely serves as the sole workhorse solver in modern large-scale CAE — instead it shines as a multigrid smoother that "quickly smooths out high-frequency error". It is best understood as the starting point of iterative solvers, not the destination.
How to Use
Set grid points (nGridNum) between 10–500 nodes for your 1D domain discretization
Define boundary conditions: left potential (phiL) and right potential (phiR) in volts or pressure units
Adjust relaxation factor omega (ω) from 0.5 to 1.99; values >1.0 accelerate convergence for elliptic problems
Run solver and observe iteration count, final residual magnitude, and convergence status
Compare different ω values to identify optimal relaxation for your grid resolution
Worked Example
Solve 1D Laplace equation on 100 grid points with phiL=100V, phiR=0V, domain [0,1m]. Standard Gauss-Seidel (ω=1.0) requires 487 iterations to residual <1e-6. Setting ω=1.85 (near theoretical optimum for N=100) converges in 84 iterations—a 5.8x speed-up. Optimal ω_theory ≈ 2/(1+π/100)≈1.937 for this configuration. Pushing ω to 1.99 diverges as eigenvalue damping exceeds stability bound.
Practical Notes
Optimal ω depends strongly on grid size: denser meshes require ω closer to 2.0; use theoretical formula ω_opt=2/(1+π/N) as starting point
Values 1.0<ω<1.5 give stable acceleration for most finite-difference Laplace problems; values >1.9 risk oscillation or divergence
Monitor final residual norm: convergence below 1e-8 typically sufficient for structural analysis and heat transfer with 64-bit arithmetic
SOR outperforms Gauss-Seidel (ω=1.0) by 3–10x on grids >50 points; speedup diminishes for very coarse grids