# Chapter 6 Elliptic Problems and Iterative Matrix Solution

## 6.1  Elliptic Equations and Matrix Inversion

In elliptic equations there is no special time-like variable and no preferred direction of propagation of the physical influence. Generally, therefore elliptic equations, such as Poisson's equation, arise in solving for steady state conditions in multiple dimensions.
A diffusive problem with constant (time independent) source ($s$) and boundary conditions, evolved forward in time, eventually reaches a steady state. When it has reached that state, $\partial /\partial t=0$. So the steady state satisfies the equation with the time derivative set to zero.
 $\nabla .\left(D\nabla \mathit{\psi }\right)=-s.$ $\left(6.1\right)$
This is an elliptic equation${}^{34}$. Indeed, if the diffusivity, $D$, is uniform, it is just Poisson's equation. The final steady state of a diffusive equation is an elliptic problem.
The linear elliptic problem in space can naturally be framed as a matrix equation by finite differencing in space and expressing the second order difference operator as a matrix multiplication, $\mathbf{B}\mathbit{\psi }$ so that
 $\mathbf{B}\mathbit{\psi }=-\mathbf{s}.$ $\left(6.2\right)$
This is the matrix inversion problem expressed in standard form. Its solution is (formally)
 $\mathbit{\psi }=-{\mathbf{B}}^{-1}\mathbf{s}.$ $\left(6.3\right)$
So to solve a linear elliptic problem requires simply a matrix inversion. Actually the hard work for the human is expressing the difference equations, and especially the boundary conditions, in the form of the matrix $\mathbf{B}$. But once that's done the computer simply has to invert the matrix. Small problems can readily be solved in this way.
As we've seen for the diffusive problem, though, the matrices involved in multidimensional problems can quickly become overwhelmingly large. The computational cost of inverting them can become excessive. What does one do? Well, we know how to solve a diffusive equation without inverting matrices, don't we. We advance it forward in time using an explicit scheme, being sure to observe the stability limits on time-step. If we take enough time steps, we'll reach a steady state. Then we'll have the solution to the corresponding elliptic problem.
This is the most appropriate way to solve a gigantic matrix inversion problem. We do not invert the matrix. Instead, we iterate $\mathit{\psi }$ until it satisfies the matrix equation $\mathbf{B}\mathbit{\psi }=-\mathbf{s}$ as accurately as we like, then we have our solution.
How do we iterate? Given what we've said already, we can think of this as the solution of a time-dependent diffusive problem. And for simplicity we'll take the diffusivity uniform.
 $\frac{\partial \mathit{\psi }}{\partial t}=D{\nabla }^{2}\mathit{\psi }+s.$ $\left(6.4\right)$
An iteration takes us from ${\mathit{\psi }}^{\left(n\right)}$ to ${\mathit{\psi }}^{\left(n+1\right)}$. It is essentially a time-step of our diffusive problem. And if we wish to avoid having to invert the matrix, we can use exactly the explicit FTCS scheme to advance it (c.f. eq. 5.2), in one space dimension
 ${\mathit{\psi }}_{j}^{\left(n+1\right)}-{\mathit{\psi }}_{j}^{\left(n\right)}=\frac{D\mathit{\Delta }t}{\mathit{\Delta }{x}^{2}}\left({\mathit{\psi }}_{j+1}^{\left(n\right)}-2{\mathit{\psi }}_{j}^{\left(n\right)}+{\mathit{\psi }}_{j-1}^{\left(n\right)}+{s}_{j}^{\left(n\right)}\mathit{\Delta }{x}^{2}/D\right).$ $\left(6.5\right)$
Observe that the term in parentheses on the right hand side of this equation is the finite difference form of the steady state equation. If $\mathit{\psi }$ satisfies the steady-state equation, then the RHS is zero, and there is no change in $\mathit{\psi }$: ${\mathit{\psi }}^{\left(n+1\right)}={\mathit{\psi }}^{\left(n\right)}$. If there is no change in $\mathit{\psi }$, the steady state equation is satisfied.
Now because we are only really interested in the final steady state, we don't worry about how accurate the time integration is. We just want to get to the final state as fast as we can. However, we do have to worry about stability, because if we use too large a time step and experience instability because of it, we will probably never reach the steady state. We know the limit of how large $\mathit{\Delta }t$ can be for this scheme. The limit is $\mathit{\Delta }t\le \mathit{\Delta }{x}^{2}/2D$. If we choose that limit, then the iterative scheme becomes:
 ${\mathit{\psi }}_{j}^{\left(n+1\right)}-{\mathit{\psi }}_{j}^{\left(n\right)}=\frac{1}{2}\left({\mathit{\psi }}_{j+1}^{\left(n\right)}-2{\mathit{\psi }}_{j}^{\left(n\right)}+{\mathit{\psi }}_{j-1}^{\left(n\right)}+\frac{{s}_{j}^{\left(n\right)}}{D}\mathit{\Delta }{x}^{2}\right).$ $\left(6.6\right)$
In ${N}_{d}$ equally-spaced dimensions, where there are $2{N}_{d}$ adjacent points in the stencil, the stability limit is $\mathit{\Delta }t=\mathit{\Delta }{x}^{2}/2{N}_{d}D$ and $2{N}_{d}$ replaces 2 in both the leading fraction and the coefficient of ${\mathit{\psi }}_{j}^{\left(n\right)}$. The general iterative form can be considered to be:
 ${\mathit{\psi }}_{j}^{\left(n+1\right)}-{\mathit{\psi }}_{j}^{\left(n\right)}=\left(\sum _{q}{a}_{q}{\mathit{\psi }}_{q}^{\left(n\right)}/\sum _{q}{a}_{q}\right)-{\mathit{\psi }}_{j}^{\left(n\right)}+\frac{{s}_{j}^{\left(n\right)}\mathit{\Delta }t}{\sum _{q}{a}_{q}},$ $\left(6.7\right)$
where the index $q$ ranges over all the $2{N}_{d}$ adjacent nodes of the difference stencil. The coefficient of stencil node $q$ is ${a}_{q}=D\mathit{\Delta }t/\mathit{\Delta }{x}^{2}$. The ${a}_{q}$ will not all be the same if dimensions are unequally spaced. The coefficient of ${\mathit{\psi }}_{j}^{\left(n\right)}$ is always $-1$, and exactly cancels the same term on the left hand side.
This scheme is referred to as Jacobi's method for iterative inversion of matrices${}^{35}$. Unfortunately it converges slowly. Fortunately we can do better using schemes inspired by Jacobi's method but using our knowledge more efficiently.
When we are mid way through updating the solution using Jacobi's method, we know some of the new values ${\mathit{\psi }}_{q}^{\left(n+1\right)}$ at the adjacent nodes. For example if we were updating in order of increasing indices a two dimension spatial configuration, then when we come to update ${\mathit{\psi }}_{\mathit{jk}}^{\left(n\right)}$, we already know ${\mathit{\psi }}_{j-1,k}^{\left(n+1\right)}$ and ${\mathit{\psi }}_{j,k-1}^{\left(n+1\right)}$. Maybe we should use those new values immediately in the difference scheme, rather than the old values at $n$. Such a scheme of using the currently updated values as available, applied to eq. (6.7) is called the Gauss-Seidel method.

## 6.2  Convergence Rate

The Gauss-Seidel method still converges nearly as slowly as the Jacobi method. The easiest way to see this (and the best way to implement the method for PDE solution) is not to update the values in increasing order of index. Instead it is better to update every other value. First update all the odd-$j$ values and then update all the even-$j$ values. The advantage is that at each stage of the update all the adjacent values in the stencil that are used have the same degree of update. The odd values are updated using the all old even values. Then the even values are updated using the all new odd values. In multiple dimensions the same effect can be achieved by updating first all the values whose indices sum to an odd value ($j+k+...=$ odd), and then those that sum to an even number. In two dimensions this choice can be illustrated by reference to a checkerboard of red and black squares representing the positions of the nodes. Fig. 6.1 illustrates the approach. The algorithm is to update first the red, then the black squares. The Red-Black updating order separates the update into two half-updates.${}^{36}$ (a) (b)
Figure 6.1: (a) One dimensional Gauss Seidel odd-even iteration produces successive solutions for each half-step that form a web that progresses upwards toward the solution. (b) In two dimensions the alternate squares to be updated are all the red (lighter shaded), then all the black.
Consider a Fourier mode${}^{37}$ of wave number ${k}_{x}=p\mathit{\pi }/L$, where $p$ is the integer mode number and $L$ is the length of the domain (one-dimensional for simplicity) at whose ends Dirichlet boundary conditions are assumed. Its half-update through eq. (6.6) (ignoring the source term), gives rise to an amplification factor
 $A={\mathit{\psi }}_{j}^{\left(n+1\right)}/{\mathit{\psi }}_{j}^{\left(n\right)}=\frac{1}{2}\left({e}^{\mathit{ip}\mathit{\pi }\mathit{\Delta }x/L}+{e}^{-\mathit{ip}\mathit{\pi }{\mathit{\Delta }}_{x}/L}\right)=\mathrm{cos}\left(p\mathit{\pi }\mathit{\Delta }x/L\right)$ $\left(6.8\right)$
The convergence process consists of the decay of the error in each mode of the system, by which $\mathit{\psi }$ is still different from the steady solution. Each mode is repetitively multiplied by $A$ at each half-step. So after $m$ full-steps ($2m$ half-steps) the mode has decayed by a factor ${A}^{2m}$. After some time, the biggest error is going to be caused by the slowest-decaying mode. That is the mode whose amplitude factor is closest to 1. Since $A=\mathrm{cos}\left(p\mathit{\pi }\mathit{\Delta }x/L\right)$, the mode with $A$ closest to 1 is the mode with the smallest wave number namely $p=1$. If the number of spatial mesh nodes, ${N}_{j}=L/\mathit{\Delta }x$ is large, then we can Taylor expand the cosine (for $p=1$)
 $A\approx 1-\frac{1}{2}{\left(\frac{\mathit{\pi }\mathit{\Delta }x}{L}\right)}^{2}=1-\frac{1}{2}{\left(\frac{\mathit{\pi }}{{N}_{j}}\right)}^{2}.$ $\left(6.9\right)$
To reduce the amplitude of the mode by a factor $1/F$ takes a number of steps $m$ such that ${A}^{2m}=1/F$, or, taking the logarithm and using the expansion $\mathrm{ln}\left(1+x\right)\approx x$, so $\mathrm{ln}A\approx -{\mathit{\pi }}^{2}/2{N}_{j}^{2}$,
 $m=\frac{1}{2}\mathrm{ln}\left(1/F\right)/\mathrm{ln}A\approx \mathrm{ln}F{\left(\frac{{N}_{j}}{\mathit{\pi }}\right)}^{2}.$ $\left(6.10\right)$
This equation shows that to converge by a specified factor, requires a number of steps proportional to ${N}_{j}^{2}$. That is a lot of iterations. Incidentally, the Jacobi iteration obviously leads to the same amplification factor $A$. The difference is that it is the factor for a full step, rather than a half step. Therefore Gauss-Seidel iteration converges only a factor of two faster than Jacobi iteration. On the plus side, for multiple dimensions, things don't get significantly worse. A square two-dimensional domain with $\mathit{\Delta }x=\mathit{\Delta }y$ has the same $A$, so it takes the same number of iterations.

## 6.3  Successive Over-Relaxation

The Gauss-Seidel method is a "successive" method where values are updated in succession, and the updated values are immediately used. It turns out that one can greatly improve the convergence rate by the simple expedient of over-correcting the error at each step. This is called "over-relaxation" and when applied to the Gauss-Seidel method is therefore called "Successive Over-Relaxation" or SOR. By analogy with eq. (6.7) it can be written
 ${\mathit{\psi }}_{j}^{\left(n+1\right)}-{\mathit{\psi }}_{j}^{\left(n\right)}=\mathit{\omega }\left[ \left(\sum _{q}{a}_{q}{\mathit{\psi }}_{q}^{\left(r\right)}/\sum _{q}{a}_{q}\right)-{\mathit{\psi }}_{j}^{\left(n\right)}+\frac{{s}_{j}^{\left(n\right)}\mathit{\Delta }t}{\sum _{q}{a}_{q}}\right],$ $\left(6.11\right)$
where $r=n$ for $q$ corresponding to odd centered stencils, and $r=n+1$ for $q$ corresponding to even. The parameter $\mathit{\omega }>1$ is the over-relaxation parameter. Strictly speaking, if $\mathit{\omega }<1$ one should speak of under-relaxation. The particular case $\mathit{\omega }=1$ is the original Gauss-Seidel scheme.
It turns out that SOR is stable for $0<\mathit{\omega }<2$. It is intuitively reasonable to guess that SOR converges faster for $\mathit{\omega }>1$, than for $\mathit{\omega }=1$. It is not at all straightforward to show how much faster it converges.${}^{38}$ Therefore we will simply summarize the facts without proving them.
• There is an optimal value of $\mathit{\omega }$ somewhere between 1 and 2, where SOR converges fastest.
• If ${A}_{J}$ is the amplification factor for the corresponding Jacobi iteration [$\mathrm{cos}\left(\mathit{\pi }\mathit{\Delta }x/L\right)$ for a uniform problem] then the optimal value is $\mathit{\omega }={\mathit{\omega }}_{b}=2/\left(1+\sqrt{1-{A}_{J}^{2}}\right)$.
• For this optimal $\mathit{\omega }$ the amplification factor for the SOR is ${A}_{\mathit{SOR}}={\mathit{\omega }}_{b}-1=\left({A}_{J}{\mathit{\omega }}_{b}/2{\right)}^{2}$. For the uniform case and large ${N}_{j}$, these imply
 ${\mathit{\omega }}_{b}\approx \frac{2}{1+\mathit{\pi }/{N}_{j}},\mathrm{ }\text{and}\mathrm{ }{A}_{\mathit{SOR}}\approx 1-\frac{2\mathit{\pi }}{{N}_{j}}.$ $\left(6.12\right)$
These facts show that near the optimal relaxation parameter the number of steps needed to converge by a factor $F$ is approximately ${N}_{j}\mathrm{ln}F/2\mathit{\pi }$ (not ${N}_{j}^{2}\mathrm{ln}F/{\mathit{\pi }}^{2}$ as with Gauss-Seidel). That is a very big benefit. However, obtaining that benefit requires one to estimate ${\mathit{\omega }}_{b}$ accurately, and for more complicated problems doing that becomes hard. Choosing $\mathit{\omega }$ well is probably the main challenge for SOR. Fig. 6.2 shows an illustrative example. Figure 6.2: Number of iterations required to converge a SOR solution of Poisson's equation with uniform source on a mesh of length ${N}_{j}=32$. It is declared converged when the maximum $\mathit{\psi }$-change in a step is less than ${10}^{-6}{\mathit{\psi }}_{\mathrm{max}}$. The minimum number of iterations is found to be 63 at $\mathit{\omega }=1.85$. This should be compared with theoretical values of $\mathrm{ln}\left({10}^{6}\right)\left({N}_{j}/2\mathit{\pi }\right)=70$ at $\mathit{\omega }=2/\left(1+\mathit{\pi }/{N}_{j}\right)=1.821$.
There are other iterative matrix solution techniques, associated with the name Krylov. Like the SOR solution technique, they use just multiplication by the matrix, not inversion. That is a big advantage for very sparse matrices arising in PDE solving. They go by names like "Conjugate Gradient", "Newton Krylov" and "GMRES". In some situations they converge faster than SOR, and they don't require careful adjustment of a relaxation parameter. However, they have their own tuning problems associated with "preconditioning". These topics are introduced very briefly in the final chapter.

## 6.4  Iteration and Nonlinear Equations

A major advantage accrues to iterative methods of solving elliptic problems. It is that we only have to multiply by the difference matrix. Because that difference matrix is extremely sparse, we need never in fact construct it in its entirety. We perform the matrix multiplication more physically by performing the small number of multiplications of adjacent stencil mesh values by coefficients. This saves immense amounts of storage space (compared with constructing the full matrix), and immense numbers of irrelevant multiplications by zero. The cost we must pay for the benefit of not constructing and inverting the matrix is that a substantial number of iterations is necessary. Generally for sizable multidimensional problems that iteration cost is far less than the savings.
Another situation where iteration becomes essential is when the differential equations are nonlinear. In the screening of electric fields by plasmas or electrolytes, for example, the source of the Poisson equation (the charge density) is a nonlinear function of the potential, $\mathit{\phi }$, in this case an exponential leading to:
 ${\nabla }^{2}\mathit{\phi }=-s=\mathrm{exp}\left(\mathit{\phi }\right)-1.$ $\left(6.13\right)$
How do we solve such an elliptic equation? It cannot be solved by matrix inversion because of the nonlinearity on the right hand side. Even if we invert the difference matrix and construct eq. (6.3): $\upphi=-{\mathbf{B}}^{-1}\mathbf{s}$, because $s$ is a nonlinear function of $\mathit{\phi }$, this expression does not constitute a solution of the problem.
The generic answer to how to solve a nonlinear problem is
1. Linearize it about the current estimate of the solution.
2. Solve or advance the linear problem.
3. Repeat from 1, until converged on the nonlinear solution.
When one knows that iteration is required anyway, because the problem is nonlinear, one has substantial incentive to use an iterative method for the linearized part of the problem as well. Very often it will cost no more effort to solve a nonlinear problem by iteration than a linear problem.

### 6.4.1  Linearization

Suppose we have potential function ${\mathit{\phi }}^{\left(n\right)}$, at step $n$, not yet a solution of the steady elliptic equation. In the neighborhood of that function, we can express the source via a Taylor expansion (at each point in the mesh):
 $s\left(\mathit{\phi }\right)=s\left({\mathit{\phi }}^{\left(n\right)}\right)+\frac{\partial s}{\partial \mathit{\phi }}\stackrel{~}{\mathit{\phi }}+\frac{1}{2!}\frac{{\partial }^{2}s}{\partial {\mathit{\phi }}^{2}}{\stackrel{~}{\mathit{\phi }}}^{2}\dots ,\mathrm{ }\text{where}\mathrm{ }\stackrel{~}{\mathit{\phi }}=\left(\mathit{\phi }-{\mathit{\phi }}^{\left(n\right)}\right).$ $\left(6.14\right)$
For values of $\mathit{\phi }$ close enough to ${\mathit{\phi }}^{\left(n\right)}$, i.e. small enough $\stackrel{~}{\mathit{\phi }}$, we can ignore all but the first two terms of this expansion. For our exponential example, substituting for $\mathit{\phi }$ and rearranging the terms, we would then obtain the linearized equation
 ${\nabla }^{2}\stackrel{~}{\mathit{\phi }}-\mathrm{exp}\left({\mathit{\phi }}^{\left(n\right)}\right)\stackrel{~}{\mathit{\phi }}=\mathrm{exp}\left({\mathit{\phi }}^{\left(n\right)}\right)-1-{\nabla }^{2}{\mathit{\phi }}^{\left(n\right)}.$ $\left(6.15\right)$
The right hand side is the residual - the amount by which the step-$n$ value fails to satisfy the differential equation. More generally one obtains, from ${\nabla }^{2}\mathit{\phi }=-s$, a linearized equation
 ${\nabla }^{2}\stackrel{~}{\mathit{\phi }}+{\frac{\partial s}{\partial \mathit{\phi }}|}_{{\mathit{\phi }}^{\left(n\right)}}\stackrel{~}{\mathit{\phi }}=-s\left({\mathit{\phi }}^{\left(n\right)}\right)-{\nabla }^{2}{\mathit{\phi }}^{\left(n\right)}.$ $\left(6.16\right)$
This equation can be solved to find $\stackrel{~}{\mathit{\phi }}$ linearly. Of course $\stackrel{~}{\mathit{\phi }}$ is our linearized estimate of the amount by which the real solution $\mathit{\phi }$ is different from the starting value at the $n$th step: ${\mathit{\phi }}^{\left(n\right)}$. If we find the solution of the linearized equation (6.16), then, since that equation is only approximate, the new value ${\mathit{\phi }}^{\left(n+1\right)}\equiv {\mathit{\phi }}^{\left(n\right)}+\stackrel{~}{\mathit{\phi }}$ is only an approximate solution of the original nonlinear equation. Presumably, though, it is closer to the actual solution. So if we simply interate the process then as $n$ increases we approach the full nonlinear solution. That is an iterative solution to the nonlinear problem using linearization.

### 6.4.2  Combining linear and nonlinear iteration

The question then arises: what method should we use to solve the linear problem to find $\stackrel{~}{\mathit{\phi }}$? It is natural to be guided by the knowledge that even if we solved the linear problem exactly, that would not give us an exact solution of the nonlinear problem. Therefore it is unnecessary to solve the linearized equation exactly. And in many cases it is in fact not even necessary to get close to the exact solution of the linearized equation for each interation of the nonlinear equation. What we then can do is to say, we'll solve the linearized equation iteratively, but we'll use only one step in our solution. In other words, ${\mathit{\phi }}^{\left(n+1\right)}$ is arrived at by doing a single advance of the linearized equation iterative scheme (e.g. a SOR advance). Then we recalculate $s$ and its derivative $\partial s/\partial \mathit{\phi }$ for the new value of $\mathit{\phi }$, and iterate.
Actually one might sometimes be able to dispense with the linear term in the linearization, by retaining, in the Taylor expansion for $s$, only the first, constant term. That would amount to using ${\nabla }^{2}{\mathit{\phi }}^{\left(n+1\right)}=\mathrm{exp}{\mathit{\phi }}^{\left(n\right)}-1$ as the equation to be solved for each step of the nonlinear iteration. Whether that will work depends upon the relative importance of the ${\nabla }^{2}\mathit{\phi }$ term in the equation. In places where ${\nabla }^{2}\mathit{\phi }$ is small, the nonlinear equation behaves like a transcendental equation for $\mathit{\phi }$: simply $\mathrm{exp}\mathit{\phi }-1\approx 0$. In that case, solving eq. (6.15), (without the ${\nabla }^{2}\mathit{\phi }$ term) is equivalent to a single Newton iteration of a root-finding problem, which is a sensible iteration to take. Without the linear term, though, negligibly small advance towards the nonlinear solution will occur.
It is hard to generalize about how fast the iteration is going to converge on the solution of the nonlinear equation. It depends upon the type of nonlinearity. But it is usually the case that if the iterative advance is chosen reasonably, then the convergence to the nonlinear solution takes no more iterations than approximately what it would require to converge as accurately to a solution of the linearized equations. In short, iterative solutions can readily accommodate nonlinearity in the equations, and produce solutions with comparable computational cost.

## Worked Example: Optimal SOR relaxation

Consider the elliptic equation
 $\frac{{\partial }^{2}\mathit{\phi }}{\partial {x}^{2}}+\frac{{\partial }^{2}\mathit{\phi }}{\partial {y}^{2}}=s\left(x,y\right)$ $\left(6.17\right)$
expressed on a cartesian grid $x=j\mathit{\Delta }x$, $j=0,1,\dots ,{N}_{x}$; $y=k\mathit{\Delta }y$, $k=0,1,\dots ,{N}_{y}$. And suppose the boundary conditions at $x=0$ and ${N}_{x}\mathit{\Delta }x$, and $y=0$ and ${N}_{y}\mathit{\Delta }y$ are $\mathit{\phi }=f\left(x,y\right)$. Find the optimum relaxation parameter $\mathit{\omega }$ for an SOR iterative solution of the system, and the resulting convergence rate.

Suppose the final solution of the system is denoted ${\mathit{\phi }}_{s}$. We can define a new dependent variable $\mathit{\psi }=\mathit{\phi }-{\mathit{\phi }}_{s}$, which is the error between some approximation of the solution ($\mathit{\phi }$) and the actual solution. Of course, while we are in the process of finding the solution, we don't know how to derive $\mathit{\psi }$ from $\mathit{\phi }$, because we don't yet know what ${\mathit{\phi }}_{s}$ is. That fact does not affect the following arguments. Substituting for $\mathit{\phi }=\mathit{\psi }+{\mathit{\phi }}_{s}$ in the differential equation and using the fact that ${\mathit{\phi }}_{s}$ exactly satisfies it and the boundary conditions, we immediately deduce that $\mathit{\psi }$ satisfies the homogeneous differential equation
 $\frac{{\partial }^{2}\mathit{\psi }}{\partial {x}^{2}}+\frac{{\partial }^{2}\mathit{\psi }}{\partial {y}^{2}}=0,$ $\left(6.18\right)$
together with homogeneous boundary conditions: $\mathit{\psi }=0$ on the boundary. Of course the final solution for $\mathit{\psi }$ is, as a consequence, simply zero. But prior to arriving at that solution, $\mathit{\psi }$ is non-zero and any iteration scheme that we use to solve for $\mathit{\phi }$ is equivalent to an iteration scheme to solve for $\mathit{\psi }$. In particular, the convergence rate of $\mathit{\psi }$ to zero is just the convergence rate of $\mathit{\phi }$ to ${\mathit{\phi }}_{s}$. All stability and convergence analysis can be done on the simpler homogeneous $\mathit{\psi }$ system eq. (6.18), and its results applied immediately to the $\mathit{\phi }$ system (6.17).
The homogeneous Jacobi iteration (see eq. 6.6) in two dimensions of different grid spacing is
 ${\mathit{\psi }}_{j,k}^{\left(n+1\right)}-{\mathit{\psi }}_{j,k}^{\left(n\right)}=\frac{1}{2}\left(\frac{{\mathit{\psi }}_{j+1,k}^{\left(n\right)}+{\mathit{\psi }}_{j-1,k}^{\left(n\right)}}{\mathit{\Delta }{x}^{2}}+\frac{{\mathit{\psi }}_{j,k+1}^{\left(n\right)}+{\mathit{\psi }}_{j,k-1}^{\left(n\right)}}{\mathit{\Delta }{y}^{2}}\right){\left(\frac{1}{\mathit{\Delta }{x}^{2}}+\frac{1}{\mathit{\Delta }{y}^{2}}\right)}^{-1}-{\mathit{\psi }}_{j,k}^{\left(n\right)}.$ $\left(6.19\right)$
Now we do a Von Neumann analysis of the homogeneous system, examining the Fourier modes of the 2-Dimensional system. They are proportional to $\mathrm{exp}i\left({k}_{x}x+{k}_{y}y\right)=\mathrm{exp}i\mathit{\pi }\left(\mathit{pj}/{N}_{x}+\mathit{qk}/{N}_{y}\right)$, where $p$ and $q$ are integers that label the mode${}^{39}$. For the $p,q$ Fourier mode, ${\mathit{\psi }}_{j+1,k}^{\left(n\right)}+{\mathit{\psi }}_{j-1,k}^{\left(n\right)}=2\mathrm{cos}\left(p\mathit{\pi }/{N}_{x}\right){\mathit{\psi }}_{j,k}^{\left(n\right)}$ and ${\mathit{\psi }}_{j,k+1}^{\left(n\right)}+{\mathit{\psi }}_{j,k-1}^{\left(n\right)}=2\mathrm{cos}\left(q\mathit{\pi }/{N}_{y}\right){\mathit{\psi }}_{j,k}^{\left(n\right)}$. So, substituting, we get the two-dimensional version of eq. (6.8)
 ${A}_{J}\equiv {\mathit{\psi }}_{j,k}^{\left(n+1\right)}/{\mathit{\psi }}_{j,k}^{\left(n\right)}=\left(\frac{\mathrm{cos}\left(p\mathit{\pi }/{N}_{x}\right)}{\mathit{\Delta }{x}^{2}}+\frac{\mathrm{cos}\left(q\mathit{\pi }/{N}_{y}\right)}{\mathit{\Delta }{y}^{2}}\right){\left(\frac{1}{\mathit{\Delta }{x}^{2}}+\frac{1}{\mathit{\Delta }{y}^{2}}\right)}^{-1}.$ $\left(6.20\right)$
The slowest-decaying mode is the longest wavelength mode: $p=1$, $q=1$. For this mode, expanding $\mathrm{cos}\mathit{\theta }\approx 1-{\mathit{\theta }}^{2}/2$, we get
 $\begin{array}{ccc}\multicolumn{1}{c}{{A}_{J}}& \approx \hfill & 1-\left(\frac{{\mathit{\pi }}^{2}}{2{N}_{x}^{2}\mathit{\Delta }{x}^{2}}+\frac{{\mathit{\pi }}^{2}}{2{N}_{y}^{2}\mathit{\Delta }{y}^{2}}\right){\left(\frac{1}{\mathit{\Delta }{x}^{2}}+\frac{1}{\mathit{\Delta }{y}^{2}}\right)}^{-1}\hfill \\ \multicolumn{1}{c}{}& =\hfill & 1-\frac{1}{2}\left[{\left(\frac{\mathit{\pi }}{{N}_{x}}\right)}^{2}\frac{\mathit{\Delta }{y}^{2}}{\mathit{\Delta }{x}^{2}+\mathit{\Delta }{y}^{2}}+{\left(\frac{\mathit{\pi }}{{N}_{y}}\right)}^{2}\frac{\mathit{\Delta }{x}^{2}}{\mathit{\Delta }{x}^{2}+\mathit{\Delta }{y}^{2}}\right]\hfill \\ \multicolumn{1}{c}{}& =\hfill & 1-\frac{1}{2}{\left(\frac{\mathit{\pi }}{{N}_{x}{N}_{y}}\right)}^{2}\frac{{N}_{y}^{2}\mathit{\Delta }{y}^{2}+{N}_{x}^{2}\mathit{\Delta }{x}^{2}}{\mathit{\Delta }{x}^{2}+\mathit{\Delta }{y}^{2}}.\hfill & \hfill \left(6.21\right)\end{array}$

For brevity in the rest of our equations, let's define a number to represent the second term
 $M\equiv {N}_{x}{N}_{y}/\sqrt{\frac{{N}_{y}^{2}\mathit{\Delta }{y}^{2}+{N}_{x}^{2}\mathit{\Delta }{x}^{2}}{\mathit{\Delta }{x}^{2}+\mathit{\Delta }{y}^{2}}}$ $\left(6.22\right)$
so that ${A}_{J}=1-\frac{1}{2}{\left(\frac{\mathit{\pi }}{M}\right)}^{2}$ and $M$ serves as a measure of the grid size, like $N$ in the one-dimensional problem.${}^{40}$ The optimal SOR relaxation factor ${\mathit{\omega }}_{b}$ is then expressed in terms of ${A}_{J}$ as
 $\begin{array}{cccc}\multicolumn{1}{c}{{\mathit{\omega }}_{b}}& =\hfill & \frac{2}{1+\sqrt{\left(1+{A}_{J}\right)\left(1-{A}_{J}\right)}}\approx \frac{2}{1+\frac{\mathit{\pi }}{M}}.\hfill & \hfill \left(6.23\right)\end{array}$

The resulting amplification factor for SOR iteration using this ${\mathit{\omega }}_{b}$ is
 ${A}_{\mathit{SOR}}={\mathit{\omega }}_{b}-1\approx 1-\frac{2\mathit{\pi }}{M},$ $\left(6.24\right)$
and the number of iterations required to reduce $\mathit{\psi }$ by a factor 1/F is (c.f. 6.10)
 $m=-\mathrm{ln}F/\mathrm{ln}{A}_{\mathit{SOR}}\approx M\frac{\mathrm{ln}F}{2\mathit{\pi }}.$ $\left(6.25\right)$
Enrichment: Outline of SOR Convergence Analysis
Assume the matrix B in eq (6.2) to be solved is arbitrary except that its diagonal entries are minus unity. That can be ensured without loss of generality by scaling the equations. It can then be separated into three parts: the diagonal, which is just minus the unit matrix $\mathbf{I}$, plus $\mathbf{U}$, those entries that multiply the old $\mathit{\psi }$-values (even nodes), plus $\mathbf{L}$, those entries that multiply the new values (odd nodes). $\mathbf{B}=-\mathbf{I}+\mathbf{U}+\mathbf{L}$. Then the SOR scheme (ignoring source) can be written
 ${\mathbit{\psi }}^{\left(n+1\right)}-{\mathbit{\psi }}^{\left(n\right)}=\mathit{\omega }\left[\left(-\mathbf{I}+\mathbf{U}\right){\mathbit{\psi }}^{\left(n\right)}+\mathbf{L}{\mathbit{\psi }}^{\left(n+1\right)}\right].$

Collecting $n$ terms together
 $\left(\mathbf{I}-\mathit{\omega }\mathbf{L}\right){\mathbit{\psi }}^{\left(n+1\right)}=\left[\left(1-\mathit{\omega }\right)\mathbf{I}+\mathit{\omega }\mathbf{U}\right]{\mathbit{\psi }}^{\left(n\right)},$

which can be written
 ${\mathbit{\psi }}^{\left(n+1\right)}=\left(\mathbf{I}-\mathit{\omega }\mathbf{L}{\right)}^{-1}\left[\left(1-\mathit{\omega }\right)\mathbf{I}+\mathit{\omega }\mathbf{U}\right]{\mathbit{\psi }}^{\left(n\right)}=\mathbf{H}{\mathbit{\psi }}^{\left(n\right)}.$

The eigenvalues of the advancing matrix $\mathbf{H}$ are the "amplification factors" for the true modes of the system. They are the solutions, $\mathit{\lambda }$, of $det\left(\mathbf{H}-\mathit{\lambda }\mathbf{I}\right)=0$. But
 $\mathbf{H}-\mathit{\lambda }\mathbf{I}=\left(\mathbf{I}-\mathit{\omega }\mathbf{L}{\right)}^{-1}\left\{\left(1-\mathit{\omega }\right)\mathbf{I}+\mathit{\omega }\mathbf{U}-\mathit{\lambda }\left(\mathbf{I}-\mathit{\omega }\mathbf{L}\right)\right\}$

So
 $det\left\{\mathit{\lambda }\mathit{\omega }\mathbf{L}+\left(1-\mathit{\lambda }-\mathit{\omega }\right)\mathbf{I}+\mathit{\omega }\mathbf{U}\right\}=0.$

Now the determinant of any matrix ${\mathit{\alpha }}^{-1}\mathbf{L}-\mathbf{D}+\mathit{\alpha }\mathbf{U}$, where $\mathbf{L}$ and $\mathbf{U}$ are lower and upper triangular parts and $\mathbf{D}$ is the diagonal, is independent of $\mathit{\alpha }$. One can see this by noticing that any term in the expansion of the determinant has equal numbers of elements from $\mathbf{U}$ as it has from $\mathbf{L}$; so the $\mathit{\alpha }$ factors cancel out. As implied by our notation, we can arrange the nodes in an appropriate order such that all the even coefficients are in the upper triangle and the odd coefficients in the lower triangle part of the matrix. This would be achieved by the simple expedient of putting all the even positions first. Actually we don't need to do the rearrangement. We just need to know it could be done. In that case, we can balance the upper and lower parts of the determinantal equation, multiplying the $\mathbf{L}$ term by ${\mathit{\lambda }}^{-1/2}$ and the $\mathbf{U}$ term by ${\mathit{\lambda }}^{1/2}$ to make it:
 $det\left\{{\mathit{\lambda }}^{1/2}\mathit{\omega }\mathbf{L}+\left(1-\mathit{\lambda }-\mathit{\omega }\right)\mathbf{I}+{\mathit{\lambda }}^{1/2}\mathit{\omega }\mathbf{U}\right\}=0,$

i.e.
 $det\left\{-\left(\mathit{\lambda }+\mathit{\omega }-1\right){\mathit{\omega }}^{-1}{\mathit{\lambda }}^{-1/2}\mathbf{I}+\mathbf{L}+\mathbf{U}\right\}=0.$

Now notice that the eigenvalues $\mathit{\mu }$ for the Jacobi iteration matrix, $\mathbf{L}+\mathbf{U}$, satisfy $det\left(-\mathit{\mu }\mathbf{I}+\mathbf{L}+\mathbf{U}\right)=0$, which is exactly the same equation with the identification $\left(\mathit{\lambda }+\mathit{\omega }-1\right){\mathit{\omega }}^{-1}{\mathit{\lambda }}^{-1/2}=\mathit{\mu }$. There's a direct mapping between eigenvalues of the Jacobi iteration and of the SOR iteration.
The relationship can be considered a quadratic equation for $\mathit{\lambda }$, given $\mathit{\mu }$ and $\mathit{\omega }$
 ${\mathit{\lambda }}^{2}+\left(2\mathit{\omega }-2-{\mathit{\omega }}^{2}{\mathit{\mu }}^{2}\right)\mathit{\lambda }+\left(\mathit{\omega }-1{\right)}^{2}=0.$

The optimum $\mathit{\omega }$ gives the smallest magnitude of the larger $\mathit{\lambda }$ solution. It occurs when the $\mathit{\lambda }$ roots coincide, i.e. when $\left(\mathit{\omega }-1-{\mathit{\omega }}^{2}{\mathit{\mu }}^{2}/2{\right)}^{2}=\left(\mathit{\omega }-1{\right)}^{2}$ whose solution is
 $\mathit{\omega }={\mathit{\omega }}_{b}=\frac{2}{1+\sqrt{1-{\mathit{\mu }}^{2}}}.$

The corresponding eigenvalue is $\mathit{\lambda }={\mathit{\omega }}_{b}-1$. For $\mathit{\omega }>{\mathit{\omega }}_{b}$, the roots for $\mathit{\lambda }$ are complex with magnitude $\mathit{\omega }-1$. Therefore SOR is stable only for $\mathit{\omega }<2$, and the convergence rate degrades linearly to zero between ${\mathit{\omega }}_{b}$ and 2.

## Exercise 6. Iterative Solution of Matrix Problems.

1. Start with your code that solved the diffusion equation explicitly. Adjust it to always take timesteps at the stability limit $\mathit{\Delta }t=\mathit{\Delta }{x}^{2}/2D$, so that:
 ${\mathit{\psi }}_{j}^{\left(n+1\right)}-{\mathit{\psi }}_{j}^{\left(n\right)}=\left(\frac{1}{2}{\mathit{\psi }}_{j+1}^{\left(n\right)}-{\mathit{\psi }}_{j}^{\left(n\right)}+\frac{1}{2}{\mathit{\psi }}_{j-1}^{\left(n\right)}+\frac{{s}_{j}^{\left(n\right)}}{2D}\mathit{\Delta }{x}^{2}\right).$

Now it is a Jacobi iterator for solving the steady-state elliptic matrix equation. Implement a convergence test that finds the maximum absolute change in $\mathit{\psi }$ and divides it by the maximum absolute $\mathit{\psi }$, giving the normalized $\mathit{\psi }$-change. Consider the iteration to be converged when the normalized $\mathit{\psi }$-change is less than (say) ${10}^{-5}$. Use it to solve
 $\frac{{d}^{2}\mathit{\psi }}{{\mathit{dx}}^{2}}=1$

on the domain $x=\left[-1,1\right]$ with boundary conditions $\mathit{\psi }=0$, with a total of ${N}_{x}$ equally-spaced nodes. Find how many iterations it takes to converge, starting from an initial state $\mathit{\psi }=0$, when
(a) ${N}_{x}=10$
(b) ${N}_{x}=30$
(c) ${N}_{x}=100$
Compare the number of iterations you require with the analytic estimate in the notes. How good is the estimate?
Now we want to check how accurate the solution really is.
(d) Solve the equation analytically, and find the value of $\mathit{\psi }$ at $x=0$, $\mathit{\psi }\left(0\right)$.
(e) For the three ${N}_{x}$ values, find the relative error${}^{41}$ in $\mathit{\psi }\left(0\right)$.
(f) Is the actual relative error the same as the convergence test value ${10}^{-5}$? Why?

2. Optional and not for credit. Turn your iterator into a SOR solver by splitting the iteration matrices up into red and black (odd and even) advancing parts. Each part-iterator then uses the latest values of $\mathit{\psi }$, that has just been updated by the other part-iterator. Also provide yourself an over-relaxation parameter $\mathit{\omega }$. Explore how fast the iterations converge as a function of ${N}_{x}$ and $\mathit{\omega }$.

Note. Although in Octave/Matlab it is convenient to implement the matrix multiplications of the advance using a literal multiplication by a big sparse matrix, one does not do that in practice. There are far more efficient ways of doing the multiplication, that avoid all the irrelevant multiplications by zero.