Expand description
Finite difference solvers for model partial differential equations.
- The heat equation
u_t = α u_xxon[0, L]with Dirichlet ends: explicit FTCS (stable forr = α Δt / Δx² ≤ ½) and Crank-Nicolson (unconditionally stable, second order in time and space), the latter solving a tridiagonal system per step by the Thomas algorithm. - The wave equation
u_tt = c² u_xxwith fixed ends by the explicit leapfrog scheme (stable for Courant numberc Δt / Δx ≤ 1, exact on the grid when it equals one). - The Poisson equation
−∇²u = fon a rectangle with Dirichlet data, by the five-point stencil solved matrix-free with conjugate gradients.
See the book entry Finite difference methods.
Enums§
- Heat
Scheme - The time-stepping scheme for
heat_equation_1d.
Functions§
- conjugate_
gradient - Conjugate gradients for a symmetric positive-definite operator
apply, from zero, to the relative residualtolerance. Ifmax_iterationsis reached first, a solution whose residual is within a factor 1000 of the target is still returned (rounding often stalls the last digits); otherwise the result is an error. - heat_
equation_ 1d - Advances
u_t = α u_xxon a uniform grid ofu0.len()points spanning[0, length](endpoints included and held atleftandright) throughstepssteps of sizedt. - poisson_
2d - Solves
−∇²u = fon[0, width] × [0, height]withu = gon the boundary, on annx × nygrid of points including the boundary. Returnsu[j][i]at(i Δx, j Δy). The five-point system is symmetric positive definite and is solved by conjugate gradients to a relative residual of1e-12. - solve_
tridiagonal - Solves the tridiagonal system with sub-diagonal
a, diagonalb, super-diagonalc(a[0]andc[n−1]unused) by the Thomas algorithm. - wave_
equation_ 1d - Advances
u_tt = c² u_xxwith fixed endsu = 0from displacementu0and velocityv0on a uniform grid spanning[0, length], by leapfrog with a Taylor first step; returns the displacement afterstepssteps of sizedt.