Método de Gauss-Jacobi ponderado

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-1)} & &+ \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-1)} &+ \cfrac{1}{10} x_{2}^{(k-1)} & &+ \cfrac{1}{10} x_{4}^{(k-1)} \\ x_{4}^{(k)} &= \cfrac{15}{8} & &- \cfrac{3}{8} x_{2}^{(k-1)} &+ \cfrac{1}{8} x_{3}^{(k-1)} & \end{alignat*}

Usando $\omega$ para acelerar la convergencia

\begin{alignat*}{6} x_{1}^{(k)} &= \omega \biggl[ \cfrac{6}{10} & &+ \cfrac{1}{10} x_{2}^{(k-1)} &- \cfrac{2}{10} x_{3}^{(k-1)} & &\biggr] + (1 - \omega) x_{1}^{(k-1)} \\ x_{2}^{(k)} &= \omega \biggl[ \cfrac{25}{11} &+ \cfrac{1}{11} x_{1}^{(k-1)} & &+ \cfrac{1}{11} x_{3}^{(k-1)} &- \cfrac{3}{11} x_{4}^{(k-1)} &\biggr] + (1 - \omega) x_{2}^{(k-1)} \\ x_{3}^{(k)} &= \omega \biggl[ \cfrac{-11}{10} &- \cfrac{2}{10} x_{1}^{(k-1)} &+ \cfrac{1}{10} x_{2}^{(k-1)} & &+ \cfrac{1}{10} x_{4}^{(k-1)} &\biggr] + (1 - \omega) x_{3}^{(k-1)} \\ x_{4}^{(k)} &= \omega \biggl[ \cfrac{15}{8} & &- \cfrac{3}{8} x_{2}^{(k-1)} &+ \cfrac{1}{8} x_{3}^{(k-1)} & &\biggr] + (1 - \omega) x_{4}^{(k-1)} \end{alignat*}

Para este ejemplo se usará $\omega = 1.05$

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)} &= 1.05 \biggl[ \frac{6 + x_{2}^{(0)} - 2 x_{3}^{(0)}}{10} \biggr] + (1 - 1.05) x_{1}^{(0)} \\ &= 1.05 \biggl[ \frac{6 + \color{blue}{0} - 2 (\color{blue}{0})}{10} \biggr] + (1 - 1.05) (\color{blue}{0}) = \color{green}{0.63} \\ x_{2}^{(1)} &= 1.05 \biggl[ \frac{25 + x_{1}^{(0)} + x_{3}^{(0)} - 3 x_{4}^{(0)}}{11} \biggr] + (1 - 1.05) x_{2}^{(0)} \\ &= 1.05 \biggl[ \frac{25 + \color{blue}{0} + \color{blue}{0} - 3 (\color{blue}{0})}{11} \biggr] + (1 - 1.05) (\color{blue}{0}) = \color{green}{2.386364} \\ x_{3}^{(1)} &= 1.05 \biggl[ \frac{-11 - 2 x_{1}^{(0)} + x_{2}^{(0)} + x_{4}^{(0)}}{10} \biggr] + (1 - 1.05) x_{3}^{(0)} \\ &= 1.05 \biggl[ \frac{-11 - 2 (\color{blue}{0}) + \color{blue}{0} + \color{blue}{0}}{10} \biggr] + (1 - 1.05) (\color{blue}{0}) = \color{green}{-1.155} \\ x_{4}^{(1)} &= 1.05 \biggl[ \frac{15 - 3 x_{2}^{(0)} + x_{3}^{(0)}}{8} \biggr] + (1 - 1.05) x_{3}^{(0)} \\ &= 1.05 \biggl[ \frac{15 - 3 (\color{blue}{0}) + \color{blue}{0}}{8} \biggr] + (1 - 1.05) (\color{blue}{0}) = \color{green}{1.96875} \end{align*}

Iteración 2

\begin{align*} x_{1}^{(2)} &= 1.05 \biggl[ \frac{6 + x_{2}^{(1)} - 2 x_{3}^{(1)}}{10} \biggr] + (1 - 1.05) x_{1}^{(1)} \\ &= 1.05 \biggl[ \frac{6 + \color{green}{2.386364} - 2 (\color{green}{-1.155})}{10} \biggr] + (1 - 1.05) (\color{green}{0.63}) = \color{red}{1.091618} \\ x_{2}^{(2)} &= 1.05 \biggl[ \frac{25 + x_{1}^{(1)} + x_{3}^{(1)} - 3 x_{4}^{(1)}}{11} \biggr] + (1 - 1.05) x_{2}^{(1)} \\ &= 1.05 \biggl[ \frac{25 + \color{green}{0.63} + (\color{green}{- 1.155}) - 3 (\color{green}{1.96875})}{11} \biggr] + (1 - 1.05) (\color{green}{2.386364}) = \color{red}{1.653153} \\ x_{3}^{(2)} &= 1.05 \biggl[ \frac{-11 - 2 x_{1}^{(1)} + x_{2}^{(1)} + x_{4}^{(1)}}{10} \biggr] + (1 - 1.05) x_{3}^{(1)} \\ &= 1.05 \biggl[ \frac{-11 - 2 (\color{green}{0.63}) + \color{green}{2.386364} + \color{green}{1.96875}}{10} \biggr] + (1 - 1.05) (\color{green}{-1.155}) = \color{red}{-0.772263} \\ x_{4}^{(2)} &= 1.05 \biggl[ \frac{15 - 3 x_{2}^{(1)} + x_{3}^{(1)}}{8} \biggr] + (1 - 1.05) x_{4}^{(1)} \\ &= 1.05 \biggl[ \frac{15 - 3 (\color{green}{2.386364}) + (\color{green}{-1.155})}{8} \biggr] + (1 - 1.05) (\color{green}{1.96875}) = \color{red}{0.779088} \end{align*}

Iteración 3

\begin{align*} x_{1}^{(3)} &= 1.05 \biggl[ \frac{6 + x_{2}^{(2)} - 2 x_{3}^{(2)}}{10} \biggr] + (1 - 1.05) x_{1}^{(2)} \\ &= 1.05 \biggl[ \frac{6 + \color{red}{1.653153} - 2 (\color{red}{-0.772263})}{10} \biggr] + (1 - 1.05) (\color{red}{1.091618}) = \color{fuchsia}{0.911175} \\ x_{2}^{(3)} &= 1.05 \biggl[ \frac{25 + x_{1}^{(2)} + x_{3}^{(2)} - 3 x_{4}^{(2)}}{11} \biggr] + (1 - 1.05) x_{2}^{(2)} \\ &= 1.05 \biggl[ \frac{25 + \color{red}{1.091618} + (\color{red}{-0.772263}) - 3 (\color{red}{0.779088})}{11} \biggr] + (1 - 1.05) (\color{red}{1.653153}) = \color{fuchsia}{2.111087} \\ x_{3}^{(3)} &= 1.05 \biggl[ \frac{-11 - 2 x_{1}^{(2)} + x_{2}^{(2)} + x_{4}^{(2)}}{10} \biggr] + (1 - 1.05) x_{3}^{(2)} \\ &= 1.05 \biggl[ \frac{-11 - 2 (\color{red}{1.091618}) + \color{red}{1.653153} + \color{red}{0.779088}}{10} \biggr] + (1 - 1.05) (\color{red}{-0.772263}) = \color{fuchsia}{-1.090241} \\ x_{4}^{(3)} &= 1.05 \biggl[ \frac{15 - 3 x_{2}^{(2)} + x_{3}^{(2)}}{8} \biggr] + (1 - 1.05) x_{4}^{(2)} \\ &= 1.05 \biggl[ \frac{15 - 3 (\color{red}{1.653153}) + (\color{red}{-0.772263})}{8} \biggr] + (1 - 1.05) (\color{red}{0.779088}) = \color{fuchsia}{1.177503} \end{align*}

Fórmula matemática

\begin{align*} k &= 1, \dots \\ & \quad i = 1, \dots, m \\ & \quad \quad x_{i}^{(k)} = \frac{\omega}{a_{ii}} \biggl( b_{i} - \sum_{\substack{j = 1 \\ j \neq i}}^{n} a_{ij} x_{j}^{(k-1)} \biggr) + (1 - \omega) x_{i}^{(k-1)} \end{align*}

Seudocódigo

function metodo_gauss_jacobi_ponderado(A,b,omega)
        m, n = tamaño(A)
        iteraciones = ...
        x_actual = [0,...,0]
        for k=1 to iteraciones do
            x_anterior = x_actual
            for i=1 to m do
                sumatoria = 0
                for j=1 to n do
                    if (j != i) then
                        sumatoria = sumatoria + A(i,j)*x_anterior(j)
                    end if
                end for
                x_actual(i) = omega/A(i,i) * (b(i) - sumatoria) + (1 - omega)*x_anterior(i)
            end for
        end for
        return x
    end function

Implementación


In [1]:
import numpy as np

def metodo_gauss_jacobi_ponderado(A, b, omega):
    m, n = A.shape
    x_actual = np.zeros(n)
    error_permitido = 0.000001
    print("{0:s} \t {1:9s} \t {2:9s} \t {3:9s} \t {4:9s} \t {5:9s}".format('k', 'x(1)', 'x(2)', 'x(3)', 'x(4)', 'error relativo %'))
    print("{0:d} \t {1:10.9f} \t {2:10.9f} \t {3:10.9f} \t {4:10.9f} \t {5:9s}".format(0, x_actual[0], x_actual[1], x_actual[2], x_actual[3], '??????????????'))
    for k in range(0,30):
        x_anterior = np.copy(x_actual)
        for i in range(0,m):
            sumatoria = b[i]
            for j in range(0,n):
                if j != i:
                    sumatoria = sumatoria - A[i,j]*x_anterior[j]
            x_actual[i] = (omega/A[i,i] * sumatoria) + (1-omega)*x_anterior[i]
        error_relativo = np.linalg.norm(((x_actual - x_anterior)/x_actual)*100)
        print("{0:d} \t {1:10.9f} \t {2:10.9f} \t {3:10.9f} \t {4:10.9f} \t {5:14.10f}".format(k+1, x_actual[0], x_actual[1], x_actual[2], x_actual[3], error_relativo))
        if error_relativo < error_permitido:
            break

In [2]:
A = np.array([[10,-1,2,0],
              [-1,11,-1,3],
              [2,-1,10,-1],
              [0,3,-1,8]])
B = np.array([6,25,-11,15])

In [3]:
metodo_gauss_jacobi_ponderado(A,B,1.05)


k 	 x(1)      	 x(2)      	 x(3)      	 x(4)      	 error relativo %
0 	 0.000000000 	 0.000000000 	 0.000000000 	 0.000000000 	 ??????????????
1 	 0.630000000 	 2.386363636 	 -1.155000000 	 1.968750000 	 200.0000000000
2 	 1.091618182 	 1.653153409 	 -0.772263068 	 0.779088068 	 171.8390593151
3 	 0.911175443 	 2.111087371 	 -1.090241310 	 1.177506914 	  53.4622795017
4 	 1.035056077 	 1.926521455 	 -0.946532378 	 0.935539830 	  33.6820623584
5 	 0.979303748 	 2.030582965 	 -1.024518722 	 1.039172811 	  14.6993083643
6 	 1.009394956 	 1.982937208 	 -0.987103495 	 0.982781235 	   7.8709441598
7 	 0.995030393 	 2.007911789 	 -1.006217329 	 1.009272079 	   3.7588305810
8 	 1.002384857 	 1.995881380 	 -0.996841210 	 0.995605105 	   1.9159117497
9 	 0.998784956 	 2.001993636 	 -1.001552679 	 1.002256042 	   0.9406241706
10 	 1.000596146 	 1.998990078 	 -0.999220991 	 0.998898415 	   0.4719948412
11 	 0.999700559 	 2.000497215 	 -1.000385849 	 1.000554981 	   0.2338195556
12 	 1.000148208 	 1.999750799 	 -0.999807344 	 0.999725830 	   0.1167182643
13 	 0.999925966 	 2.000123509 	 -1.000095710 	 1.000137118 	   0.0579976946
14 	 1.000036769 	 1.999938356 	 -0.999952301 	 0.999931950 	   0.0288989510
15 	 0.999981672 	 2.000030632 	 -1.000023724 	 1.000033935 	   0.0143755515
16 	 1.000009115 	 1.999984737 	 -0.999988185 	 0.999983128 	   0.0071583417
17 	 0.999995461 	 2.000007592 	 -1.000005879 	 1.000008404 	   0.0035622703
18 	 1.000002259 	 1.999996219 	 -0.999997073 	 0.999995819 	   0.0017734128
19 	 0.999998875 	 2.000001881 	 -1.000001457 	 1.000002082 	   0.0008826502
20 	 1.000000560 	 1.999999063 	 -0.999999275 	 0.999998964 	   0.0004393716
21 	 0.999999721 	 2.000000466 	 -1.000000361 	 1.000000516 	   0.0002186932
22 	 1.000000139 	 1.999999768 	 -0.999999820 	 0.999999743 	   0.0001088588
23 	 0.999999931 	 2.000000116 	 -1.000000089 	 1.000000128 	   0.0000541846
24 	 1.000000034 	 1.999999943 	 -0.999999955 	 0.999999936 	   0.0000269711
25 	 0.999999983 	 2.000000029 	 -1.000000022 	 1.000000032 	   0.0000134250
26 	 1.000000009 	 1.999999986 	 -0.999999989 	 0.999999984 	   0.0000066824
27 	 0.999999996 	 2.000000007 	 -1.000000005 	 1.000000008 	   0.0000033262
28 	 1.000000002 	 1.999999996 	 -0.999999997 	 0.999999996 	   0.0000016557
29 	 0.999999999 	 2.000000002 	 -1.000000001 	 1.000000002 	   0.0000008241