Where the matrix comes from
What this page answers
The class page says an elliptic problem is one where the answer is a value at every point and nothing travels. It also says a computer solves one by turning it into a linear system. It does not show the turning. This page integrates one problem by parts, assembles the matrix element by element, and checks the answer against the one function that can be written down.
It closes the discretisation row of the measured gaps: the book uses the word and never shows the step it names.
The mathematics
Take the simplest elliptic problem on the unit interval:
A classical solution needs two derivatives, and a piecewise-linear guess has none at the joins. So the equation is rewritten in a form that a rougher function can satisfy: multiply by a test function that also vanishes at the ends, and integrate over the interval:
Integrating the left side by parts moves one derivative from onto :
The boundary term is zero because vanishes there. What is left is the weak form:
Both sides now need only one derivative, so a piecewise-linear is allowed. The equation has become weaker on purpose: a solution of the classical equation satisfies it, and the weaker condition is the one a computer can meet.
The matrix. Split the interval into pieces of width , with nodes , and let be the hat function that is at node , at every other node, and linear in between. Write and choose for each . Substituting gives
which is a linear system with
Every entry of is computed from one element. On the element , has slope and has slope , so
Adding the contribution from the element on the other side, where again has slope , gives the diagonal and the off-diagonals . So
the same matrix whichever is chosen. That is the point worth taking away: the matrix is the operator, and the load vector is the data. Change and only changes.
The load. With , , the area of the hat. So , not — the factor is the width of the region over which the constant acts, and leaving it out scales the answer by .
The check. For with zero ends, the exact solution is . With the program below returns , , at , which are exactly , and . The nodal values are exact here, and the reason is visible in the matrix: says , which is . The exact solution is a quadratic, and a quadratic's second difference is exactly times its second derivative. The two difference equations are the same equation, so their solutions agree at the nodes. That is a property of this problem, not a rule: a different loses it.
The code
The program assembles the matrix for from the element rule, applies the load per node, solves exactly, and compares each nodal value with the exact solution at the same point.
The assembled matrix, the solve, and the exact values
import sympy as sp
n = 4
h = sp.Rational(1, n)
K = sp.zeros(n - 1, n - 1)
for i in range(n - 1):
K[i, i] = 2 / h
if i:
K[i, i - 1] = -1 / h
if i < n - 2:
K[i, i + 1] = -1 / h
f = h * sp.ones(n - 1, 1)
u = K.LUsolve(f)
print("h K =", (K * h).tolist())
for i in range(n - 1):
x = (i + 1) * h
exact = x * (1 - x) / 2
diff = u[i] - exact
print(f"x = {x} u_h = {u[i]} exact = {exact} diff = {diff}")
h K = [[2, -1, 0], [-1, 2, -1], [0, -1, 2]]
x = 1/4 u_h = 3/32 exact = 3/32 diff = 0
x = 1/2 u_h = 1/8 exact = 1/8 diff = 0
x = 3/4 u_h = 3/32 exact = 3/32 diff = 0
The first line is rather than , because that is the matrix that does not depend on : the in front is the whole of the mesh's effect on the operator. The three differences are zero, so the discretisation error at the nodes is not merely small — for this load it is absent, and the page above says why.
The theory
The weak form is what a finite element method actually solves, and three consequences follow from it.
- The choice of test space is the method. Taking from the same space as is Galerkin's choice, and it is what makes symmetric. Taking from a different space is a mixed method, which is the saddle-point class.
- The matrix is sparse because the basis is local. is nonzero only on two elements, so is nonzero only when and share an element. A basis with global support would give a dense matrix for the same operator.
- A better solution needs a better space. Refining the mesh makes smaller and larger, and the error falls as in the energy norm for a smooth solution. Raising the polynomial degree inside each element is the other route, and it converges faster when the solution is smooth.
The stability of the method is a property of the weak form rather than of the solve. The bilinear form is coercive on the space of functions that vanish at the ends. That is what gives its positive definiteness, and it is what lets the conjugate-gradient family be used on it. Briggs, Henson and McCormick's multigrid text opens with this example for exactly that reason. It is the cleanest case in which the operator, the matrix and the solver can all be seen at once.
What it will not do: nodal exactness does not generalise. It held because the test functions reproduce quadratics and the exact solution was a quadratic. A variable load, a coefficient that varies with , or two dimensions all lose it, and then the error is rather than zero.
What this cost
The matrix has nonzeros for unknowns in one dimension, and each row costs a handful of arithmetic operations to assemble. Solving it by a direct factorisation costs for this banded matrix. An iterative method costs a few matrix-vector products of each. The number of those products grows as the mesh refines, unless the method is preconditioned or multigrid is used.
The accuracy in the energy norm is for a smooth solution, so halving quarters the error and doubles the unknowns. In two dimensions the same argument gives with unknowns, which is where the cost of a refined mesh starts to bite.
What it will not do: it will not choose for you. It will not fix a singular problem where the exact solution has a corner. And it will not give the exact value between nodes: the piecewise-linear answer interpolates the nodal values, so the error between nodes is the one.
Back to the map
Elliptic is the class page this works under. One matrix, two errors is what the solve of this is exposed to. Home is the summary.