Método de Gauss-Seidel
Resolver el sistema de ecuaciones
\begin{align*}
10 x_{1} - x_{2} + 2 x_{3} &= 6 \\
-x_{1} + 11 x_{2} - x_{3} + 3 x_{4} &= 25 \\
2 x_{1} - x_{2} + 10 x_{3} - x_{4} &= -11 \\
3 x_{2} - x_{3} + 8 x_{4} &= 15
\end{align*}
Despejando $x_{i}$
\begin{alignat*}{5}
x_{1}^{(k)} &= \cfrac{6}{10} & &+ \cfrac{1}{10} x_{2}^{(k-1)} &- \cfrac{2}{10} x_{3}^{(k-1)} & \\
x_{2}^{(k)} &= \cfrac{25}{11} &+ \cfrac{1}{11} x_{1}^{(k)} & &+ \cfrac{1}{11} x_{3}^{(k-1)} &- \cfrac{3}{11} x_{4}^{(k-1)} \\
x_{3}^{(k)} &= \cfrac{-11}{10} &- \cfrac{2}{10} x_{1}^{(k)} &+ \cfrac{1}{10} x_{2}^{(k)} & &+ \cfrac{1}{10} x_{4}^{(k-1)} \\
x_{4}^{(k)} &= \cfrac{15}{8} & &- \cfrac{3}{8} x_{2}^{(k)} &+ \cfrac{1}{8} x_{3}^{(k)} &
\end{alignat*}
Iteración 0
\begin{align*}
x_{1}^{(0)} &= \color{blue}{0} \\
x_{2}^{(0)} &= \color{blue}{0} \\
x_{3}^{(0)} &= \color{blue}{0} \\
x_{4}^{(0)} &= \color{blue}{0}
\end{align*}
Iteración 1
\begin{align*}
x_{1}^{(1)} &= \frac{6 + x_{2}^{(0)} - 2 x_{3}^{(0)}}{10} = \frac{6 + \color{blue}{0} - 2 (\color{blue}{0})}{10} = \color{green}{0.6} \\
x_{2}^{(1)} &= \frac{25 + x_{1}^{(1)} + x_{3}^{(0)} - 3 x_{4}^{(0)}}{11} = \frac{25 + \color{green}{0.6} + \color{blue}{0} - 3 (\color{blue}{0})}{11} = \color{green}{2.327273} \\
x_{3}^{(1)} &= \frac{-11 - 2 x_{1}^{(1)} + x_{2}^{(1)} + x_{4}^{(0)}}{10} = \frac{-11 - 2 (\color{green}{0.6}) + \color{green}{2.327273} + \color{blue}{0}}{10} = \color{green}{-0.987273} \\
x_{4}^{(1)} &= \frac{15 - 3 x_{2}^{(1)} + x_{3}^{(1)}}{8} = \frac{15 - 3 (\color{green}{2.327273}) + (\color{green}{-0.987273})}{8} = \color{green}{0.878864}
\end{align*}
Iteración 2
\begin{align*}
x_{1}^{(2)} &= \frac{6 + x_{2}^{(1)} - 2 x_{3}^{(1)}}{10} = \frac{6 + \color{green}{2.327273} - 2 (\color{green}{-0.987273})}{10} = \color{red}{1.030182} \\
x_{2}^{(2)} &= \frac{25 + x_{1}^{(2)} + x_{3}^{(1)} - 3 x_{4}^{(1)}}{11} = \frac{25 + \color{red}{1.030182} + (\color{green}{-0.987273}) - 3 (\color{green}{0.878864})}{11} = \color{red}{2.036938} \\
x_{3}^{(2)} &= \frac{-11 - 2 x_{1}^{(2)} + x_{2}^{(2)} + x_{4}^{(1)}}{10} = \frac{-11 - 2 (\color{red}{1.030182}) + \color{red}{2.036938} + \color{green}{0.878864}}{10} = \color{red}{-1.014456} \\
x_{4}^{(2)} &= \frac{15 - 3 x_{2}^{(2)} + x_{3}^{(2)}}{8} = \frac{15 - 3 (\color{red}{2.036938}) + (\color{red}{-1.014456})}{8} = \color{red}{0.984341}
\end{align*}
Iteración 3
\begin{align*}
x_{1}^{(3)} &= \frac{6 + x_{2}^{(2)} - 2 x_{3}^{(2)}}{10} = \frac{6 + \color{red}{2.036938} - 2 (\color{red}{-1.014456})}{10} = \color{fuchsia}{1.006585} \\
x_{2}^{(3)} &= \frac{25 + x_{1}^{(2)} + x_{3}^{(2)} - 3 x_{4}^{(2)}}{11} = \frac{25 + \color{fuchsia}{1.006585} + (\color{red}{-1.014456}) - 3 (\color{red}{0.984341})}{11} = \color{fuchsia}{2.003555} \\
x_{3}^{(3)} &= \frac{-11 - 2 x_{1}^{(2)} + x_{2}^{(2)} + x_{4}^{(2)}}{10} = \frac{-11 - 2 (\color{fuchsia}{1.006585}) + \color{fuchsia}{2.003555} + \color{red}{0.984341}}{10} = \color{fuchsia}{-1.002527} \\
x_{4}^{(3)} &= \frac{15 - 3 x_{2}^{(2)} + x_{3}^{(2)}}{8} = \frac{15 - 3 (\color{fuchsia}{2.003555}) + (\color{fuchsia}{-1.002527})}{8} = \color{fuchsia}{0.998351}
\end{align*}
Patrón de cálculo
\begin{align*}
a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\
a_{21} x_{1} + a_{22} x_{2} + a_{23} x_{3} + a_{24} x_{4} &= b_{2} \\
a_{31} x_{1} + a_{32} x_{2} + a_{33} x_{3} + a_{34} x_{4} &= b_{3} \\
a_{41} x_{1} + a_{42} x_{2} + a_{43} x_{3} + a_{44} x_{4} &= b_{4}
\end{align*}
Despejando $x_{i}$
\begin{alignat*}{5}
x_{1} &= \cfrac{b_{1}}{a_{11}} & &- \cfrac{a_{12}}{a_{11}} x_{2} &- \cfrac{a_{13}}{a_{11}} x_{3} &- \cfrac{a_{14}}{a_{11}} x_{4} \\
x_{2} &= \cfrac{b_{2}}{a_{22}} &- \cfrac{a_{21}}{a_{22}} x_{1} & &- \cfrac{a_{23}}{a_{22}} x_{3} &- \cfrac{a_{24}}{a_{22}} x_{4} \\
x_{3} &= \cfrac{b_{3}}{a_{33}} &- \cfrac{a_{31}}{a_{33}} x_{1} &- \cfrac{a_{32}}{a_{33}} x_{2} & &- \cfrac{a_{34}}{a_{33}} x_{4} \\
x_{4} &= \cfrac{b_{4}}{a_{44}} &- \cfrac{a_{41}}{a_{44}} x_{1} &- \cfrac{a_{42}}{a_{44}} x_{2} &- \cfrac{a_{43}}{a_{44}} x_{3} &
\end{alignat*}
Primer patrón
\begin{alignat*}{5}
x_{1}^{(\color{blue}{1})} &= \cfrac{b_{1}}{a_{11}} & &- \cfrac{a_{12}}{a_{11}} x_{2}^{(\color{blue}{1} - 1)} &- \cfrac{a_{13}}{a_{11}} x_{3}^{(\color{blue}{1} - 1)} &- \cfrac{a_{14}}{a_{11}} x_{4}^{(\color{blue}{1} - 1)} \\
x_{2}^{(\color{blue}{1})} &= \cfrac{b_{2}}{a_{22}} &- \cfrac{a_{21}}{a_{22}} x_{1}^{(\color{blue}{1})} & &- \cfrac{a_{23}}{a_{22}} x_{3}^{(\color{blue}{1} - 1)} &- \cfrac{a_{24}}{a_{22}} x_{4}^{(\color{blue}{1} - 1)} \\
x_{3}^{(\color{blue}{1})} &= \cfrac{b_{3}}{a_{33}} &- \cfrac{a_{31}}{a_{33}} x_{1}^{(\color{blue}{1})} &- \cfrac{a_{32}}{a_{33}} x_{2}^{(\color{blue}{1})} & &- \cfrac{a_{34}}{a_{33}} x_{4}^{(\color{blue}{1} - 1)} \\
x_{4}^{(\color{blue}{1})} &= \cfrac{b_{4}}{a_{44}} &- \cfrac{a_{41}}{a_{44}} x_{1}^{(\color{blue}{1})} &- \cfrac{a_{42}}{a_{44}} x_{2}^{(\color{blue}{1})} &- \cfrac{a_{43}}{a_{44}} x_{3}^{(\color{blue}{1})} & \\
x_{1}^{(\color{green}{2})} &= \cfrac{b_{1}}{a_{11}} & &- \cfrac{a_{12}}{a_{11}} x_{2}^{(\color{green}{2} - 1)} &- \cfrac{a_{13}}{a_{11}} x_{3}^{(\color{green}{2} - 1)} &- \cfrac{a_{14}}{a_{11}} x_{4}^{(\color{green}{2} - 1)} \\
x_{2}^{(\color{green}{2})} &= \cfrac{b_{2}}{a_{22}} &- \cfrac{a_{21}}{a_{22}} x_{1}^{(\color{green}{2})} & &- \cfrac{a_{23}}{a_{22}} x_{3}^{(\color{green}{2} - 1)} &- \cfrac{a_{24}}{a_{22}} x_{4}^{(\color{green}{2} - 1)} \\
x_{3}^{(\color{green}{2})} &= \cfrac{b_{3}}{a_{33}} &- \cfrac{a_{31}}{a_{33}} x_{1}^{(\color{green}{2})} &- \cfrac{a_{32}}{a_{33}} x_{2}^{(\color{green}{2})} & &- \cfrac{a_{34}}{a_{33}} x_{4}^{(\color{green}{2} - 1)} \\
x_{4}^{(\color{green}{2})} &= \cfrac{b_{4}}{a_{44}} &- \cfrac{a_{41}}{a_{44}} x_{1}^{(\color{green}{2})} &- \cfrac{a_{42}}{a_{44}} x_{2}^{(\color{green}{2})} &- \cfrac{a_{43}}{a_{44}} x_{3}^{(\color{green}{2})} & \\
x_{1}^{(\color{red}{3})} &= \cfrac{b_{1}}{a_{11}} & &- \cfrac{a_{12}}{a_{11}} x_{2}^{(\color{red}{3} - 1)} &- \cfrac{a_{13}}{a_{11}} x_{3}^{(\color{red}{3} - 1)} &- \cfrac{a_{14}}{a_{11}} x_{4}^{(\color{red}{3} - 1)} \\
x_{2}^{(\color{red}{3})} &= \cfrac{b_{2}}{a_{22}} &- \cfrac{a_{21}}{a_{22}} x_{1}^{(\color{red}{3})} & &- \cfrac{a_{23}}{a_{22}} x_{3}^{(\color{red}{3} - 1)} &- \cfrac{a_{24}}{a_{22}} x_{4}^{(\color{red}{3} - 1)} \\
x_{3}^{(\color{red}{3})} &= \cfrac{b_{3}}{a_{33}} &- \cfrac{a_{31}}{a_{33}} x_{1}^{(\color{red}{3})} &- \cfrac{a_{32}}{a_{33}} x_{2}^{(\color{red}{3})} & &- \cfrac{a_{34}}{a_{33}} x_{4}^{(\color{red}{3} - 1)} \\
x_{4}^{(\color{red}{3})} &= \cfrac{b_{4}}{a_{44}} &- \cfrac{a_{41}}{a_{44}} x_{1}^{(\color{red}{3})} &- \cfrac{a_{42}}{a_{44}} x_{2}^{(\color{red}{3})} &- \cfrac{a_{43}}{a_{44}} x_{3}^{(\color{red}{3})} &
\end{alignat*}
Lo anterior puede escribirse como
\begin{alignat*}{5}
x_{1}^{(k)} &= \cfrac{b_{1}}{a_{11}} & &- \cfrac{a_{12}}{a_{11}} x_{2}^{(k-1)} &- \cfrac{a_{13}}{a_{11}} x_{3}^{(k-1)} &- \cfrac{a_{14}}{a_{11}} x_{4}^{(k-1)} \\
x_{2}^{(k)} &= \cfrac{b_{2}}{a_{22}} &- \cfrac{a_{21}}{a_{22}} x_{1}^{(k)} & &- \cfrac{a_{23}}{a_{22}} x_{3}^{(k-1)} &- \cfrac{a_{24}}{a_{22}} x_{4}^{(k-1)} \\
x_{3}^{(k)} &= \cfrac{b_{3}}{a_{33}} &- \cfrac{a_{31}}{a_{33}} x_{1}^{(k)} &- \cfrac{a_{32}}{a_{33}} x_{2}^{(k)} & &- \cfrac{a_{34}}{a_{33}} x_{4}^{(k-1)} \\
x_{4}^{(k)} &= \cfrac{b_{4}}{a_{44}} &- \cfrac{a_{41}}{a_{44}} x_{1}^{(k)} &- \cfrac{a_{42}}{a_{44}} x_{2}^{(k)} &- \cfrac{a_{43}}{a_{44}} x_{3}^{(k)} &
\end{alignat*}
para $k = 1, \dots,$
Segundo patrón
\begin{alignat*}{5}
x_{\color{blue}{1}}^{(k)} &= \cfrac{b_{\color{blue}{1}}}{a_{\color{blue}{11}}} & &- \cfrac{a_{\color{blue}{1}2}}{a_{\color{blue}{11}}} x_{2}^{(k-1)} &- \cfrac{a_{\color{blue}{1}3}}{a_{\color{blue}{11}}} x_{3}^{(k-1)} &- \cfrac{a_{\color{blue}{1}4}}{a_{\color{blue}{11}}} x_{4}^{(k-1)} \\
x_{\color{green}{2}}^{(k)} &= \cfrac{b_{\color{green}{2}}}{a_{\color{green}{22}}} &- \cfrac{a_{\color{green}{2}1}}{a_{\color{green}{22}}} x_{1}^{(k)} & &- \cfrac{a_{\color{green}{2}3}}{a_{\color{green}{22}}} x_{3}^{(k-1)} &- \cfrac{a_{\color{green}{2}4}}{a_{\color{green}{22}}} x_{4}^{(k-1)} \\
x_{\color{red}{3}}^{(k)} &= \cfrac{b_{\color{red}{3}}}{a_{\color{red}{33}}} &- \cfrac{a_{\color{red}{3}1}}{a_{\color{red}{33}}} x_{1}^{(k)} &- \cfrac{a_{\color{red}{3}2}}{a_{\color{red}{33}}} x_{2}^{(k)} & &- \cfrac{a_{\color{red}{3}4}}{a_{\color{red}{33}}} x_{4}^{(k-1)} \\
x_{\color{fuchsia}{4}}^{(k)} &= \cfrac{b_{\color{fuchsia}{4}}}{a_{\color{fuchsia}{44}}} &- \cfrac{a_{\color{fuchsia}{4}1}}{a_{\color{fuchsia}{44}}} x_{1}^{(k)} &- \cfrac{a_{\color{fuchsia}{4}2}}{a_{\color{fuchsia}{44}}} x_{2}^{(k)} &- \cfrac{a_{\color{fuchsia}{4}3}}{a_{\color{fuchsia}{44}}} x_{3}^{(k)} &
\end{alignat*}
Lo anterior puede ser escrito como
\begin{equation*}
x_{i}^{(k)} = \frac{1}{a_{ii}} \biggl( b_{i} - \sum a_{i?} x_{?}^{(k)} - \sum a_{i?} x_{?}^{(k-1)} \biggr)
\end{equation*}
para $i = 1, \dots, m$
Tercer patrón
\begin{alignat*}{5}
x_{1}^{(k)} &= \cfrac{b_{1}}{a_{11}} & &- \cfrac{a_{1\color{green}{2}}}{a_{11}} x_{\color{green}{2}}^{(k-1)} &- \cfrac{a_{1\color{red}{3}}}{a_{11}} x_{\color{red}{3}}^{(k-1)} &- \cfrac{a_{1\color{fuchsia}{4}}}{a_{11}} x_{\color{fuchsia}{4}}^{(k-1)} \\
x_{2}^{(k)} &= \cfrac{b_{2}}{a_{22}} &- \cfrac{a_{2\color{blue}{1}}}{a_{22}} x_{\color{blue}{1}}^{(k)} & &- \cfrac{a_{2\color{red}{3}}}{a_{22}} x_{\color{red}{3}}^{(k-1)} &- \cfrac{a_{2\color{fuchsia}{4}}}{a_{22}} x_{\color{fuchsia}{4}}^{(k-1)} \\
x_{3}^{(k)} &= \cfrac{b_{3}}{a_{33}} &- \cfrac{a_{3\color{blue}{1}}}{a_{33}} x_{\color{blue}{1}}^{(k)} &- \cfrac{a_{3\color{green}{2}}}{a_{33}} x_{\color{green}{2}}^{(k)} & &- \cfrac{a_{3\color{fuchsia}{4}}}{a_{33}} x_{\color{fuchsia}{4}}^{(k-1)} \\
x_{4}^{(k)} &= \cfrac{b_{4}}{a_{44}} &- \cfrac{a_{4\color{blue}{1}}}{a_{44}} x_{\color{blue}{1}}^{(k)} &- \cfrac{a_{4\color{green}{2}}}{a_{44}} x_{\color{green}{2}}^{(k)} &- \cfrac{a_{4\color{red}{3}}}{a_{44}} x_{\color{red}{3}}^{(k)} &
\end{alignat*}
Lo anterior puede ser escrito como
\begin{equation*}
x_{i}^{(k)} = \frac{1}{a_{ii}} \biggl( b_{i} - \sum_{j = 1}^{i-1} a_{ij} x_{j}^{(k)} - \sum_{j = i+1}^{n} a_{ij} x_{j}^{(k-1)} \biggr)
\end{equation*}
para $j = 1, \dots, n$
Fórmula matemática
\begin{align*}
k &= 1, \dots \\
& \quad i = 1, \dots, m \\
& \quad \quad x_{i}^{(k)} = \frac{1}{a_{ii}} \biggl( b_{i} - \sum_{j = 1}^{i-1} a_{ij} x_{j}^{(k)} - \sum_{j = i+1}^{n} a_{ij} x_{j}^{(k-1)} \biggr)
\end{align*}
Seudocódigo
function gauss_seidel(A, b)
m, n = tamaño(A)
x_actual = [0,...,0]
for k=1 to iteraciones do
for i=1 to m do
x_anterior = x_actual
sumatoria = b(i)
for j=1 to i-1 do
sumatoria = sumatoria - A(i,j)*x_actual(j)
end for
for j=i+1 to n do
sumatoria = sumatoria - A(i,j)*x_anterior(j)
end for
x_actual(i) = sumatoria/A(i,i)
end for
end for
return x
end function
Implementación