Jacobi iteration for a three-variable tridiagonal system (source code)

= Jacobi iteration for a three-variable tridiagonal system
{c}
{title2=$\rho(B)=\sqrt2/4$}

Consider the original <linear system> with a <symmetric matrix> that is also a <tridiagonal matrix>:
$$
A=\begin{pmatrix}4&-1&0\\-1&4&-1\\0&-1&4\end{pmatrix},\qquad x_*=\begin{pmatrix}1\\2\\3\end{pmatrix},\qquad b=Ax_*=\begin{pmatrix}2\\4\\10\end{pmatrix}.
$$
Here $D=4I$ and the <Jacobi method> reads
$$
x_1^{(k+1)}=\frac{2+x_2^{(k)}}4,\qquad x_2^{(k+1)}=\frac{4+x_1^{(k)}+x_3^{(k)}}4,\qquad x_3^{(k+1)}=\frac{10+x_2^{(k)}}4.
$$
Starting from $x^{(0)}=0$, the first three <vectors> are
$$
x^{(1)}=\begin{pmatrix}1/2\\1\\5/2\end{pmatrix},\qquad x^{(2)}=\begin{pmatrix}3/4\\7/4\\11/4\end{pmatrix},\qquad x^{(3)}=\begin{pmatrix}15/16\\15/8\\47/16\end{pmatrix}.
$$
Every right-hand side uses superscript $k$, including the middle row, even when a new first coordinate has already been computed.

\Image[/jacobi-simultaneous-component-update.png]
{title=Simultaneous old-to-new component updates in the <Jacobi method>, compared with immediate reuse in the <Gauss-Seidel method>}

For comparison, a first <Gauss-Seidel method> sweep in coordinate order $1,2,3$ gives
$$
x_1^{(1)}=\frac24=\frac12,\qquad x_2^{(1)}=\frac{4+1/2+0}4=\frac98,\qquad x_3^{(1)}=\frac{10+9/8}4=\frac{89}{32}.
$$
The new first coordinate enters the middle update, and the new second coordinate enters the final update. Accidentally overwriting old coordinates during a <Jacobi method> sweep therefore changes the mathematical method.