Transformar el sistema de ecuaciones en un sistema triangular inferior
\begin{equation*} \begin{bmatrix} 3 & -0.1 & -0.2 \\ 0.1 & 7 & -0.3 \\ 0.3 & -0.2 & 10 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 7.85 \\ -19.3 \\ 71.4 \end{bmatrix} \end{equation*}Tercera fila pivote
\begin{equation*} \begin{bmatrix} 3 - \frac{-0.2}{10} (0.3) & -0.1 - \frac{-0.2}{10} (-0.2) & -0.2 - \frac{-0.2}{10} (10) \\ 0.1 - \frac{-0.3}{10} (0.3) & 7 - \frac{-0.3}{10} (-0.2) & -0.3 - \frac{-0.3}{10} (10) \\ 0.3 & -0.2 & 10 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 7.85 - \frac{-0.2}{10} (71.4) \\ -19.3 - \frac{-0.3}{10} (71.4) \\ 71.4 \end{bmatrix} \end{equation*}Simplificando
\begin{equation*} \begin{bmatrix} 3.006 & -0.104 & 0 \\ 0.109 & 6.994 & 0 \\ 0.3 & -0.2 & 10 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 9.278 \\ -17.158 \\ 71.4 \end{bmatrix} \end{equation*}Segunda fila pivote
\begin{equation*} \begin{bmatrix} 3.006 - \frac{-0.104}{6.994} (0.109) & -0.104 - \frac{-0.104}{6.994} (6.994) & 0 \\ 0.109 & 6.994 & 0 \\ 0.3 & -0.2 & 10 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 9.278 - \frac{-0.104}{6.994} (-17.158) \\ -17.158 \\ 71.4 \end{bmatrix} \end{equation*}Simplificando
\begin{equation*} \begin{bmatrix} 3.007621 & 0 & 0 \\ 0.109 & 6.994 & 0 \\ 0.3 & -0.2 & 10 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 9.022862 \\ -17.158 \\ 71.4 \end{bmatrix} \end{equation*}Expandiendo y agrupando términos
\begin{align*} \bigg( a_{11} - \frac{a_{13}}{a_{33}} a_{41} \bigg) x_{1} + \bigg( a_{12} - \frac{a_{13}}{a_{33}} a_{42} \bigg) x_{2} + \bigg( a_{13} - \frac{a_{13}}{a_{33}} a_{43} \bigg) x_{3} + \bigg( a_{14} - \frac{a_{14}}{a_{33}} a_{44} \bigg) x_{4} &= b_{1} - \frac{a_{14}}{a_{44}} b_{4} \\ \bigg( a_{21} - \frac{a_{23}}{a_{33}} a_{41} \bigg) x_{1} + \bigg( a_{22} - \frac{a_{23}}{a_{33}} a_{42} \bigg) x_{2} + \bigg( a_{23} - \frac{a_{23}}{a_{33}} a_{43} \bigg) x_{3} + \bigg( a_{24} - \frac{a_{24}}{a_{33}} a_{44} \bigg) x_{4} &= b_{2} - \frac{a_{24}}{a_{44}} b_{4} \\ \bigg( a_{31} - \frac{a_{23}}{a_{33}} a_{41} \bigg) x_{1} + \bigg( a_{32} - \frac{a_{23}}{a_{33}} a_{42} \bigg) x_{2} + \bigg( a_{33} - \frac{a_{23}}{a_{33}} a_{43} \bigg) x_{3} + \bigg( a_{34} - \frac{a_{34}}{a_{33}} a_{44} \bigg) x_{4} &= b_{3} - \frac{a_{34}}{a_{44}} b_{4} \\ a_{41} x_{1} + a_{42} x_{2} + a_{43} x_{3} + a_{44} x_{4} &= b_{4} \end{align*}Usando un cambio de variable
\begin{alignedat}{5} a'_{11} x_{1} & {}+{} a'_{12} x_{2} & {}+{} a'_{13} x_{3} & & {}={} b'_{1} \\ a'_{21} x_{1} & {}+{} a'_{22} x_{2} & {}+{} a'_{23} x_{3} & & {}={} b'_{2} \\ a'_{31} x_{1} & {}+{} a'_{32} x_{2} & {}+{} a'_{33} x_{3} & & {}={} b'_{3} \\ a_{41} x_{1} & {}+{} a_{42} x_{2} & {}+{} a_{43} x_{3} & {}+{} a_{44} x_{4} & {}={} b_{4} \end{alignedat}Expandiendo y agrupando términos
\begin{align*} \bigg( a'_{11} - \frac{a'_{13}}{a'_{33}} a'_{31} \bigg) x_{1} + \bigg( a'_{12} - \frac{a'_{13}}{a'_{33}} a'_{32} \bigg) x_{2} + \bigg( a'_{13} - \frac{a'_{13}}{a'_{33}} a'_{33} \bigg) x_{3} &= b'_{1} - \frac{a'_{13}}{a'_{33}} b'_{3} \\ \bigg( a'_{21} - \frac{a'_{23}}{a'_{33}} a'_{31} \bigg) x_{1} + \bigg( a'_{22} - \frac{a'_{23}}{a'_{33}} a'_{32} \bigg) x_{2} + \bigg( a'_{23} - \frac{a'_{23}}{a'_{33}} a'_{33} \bigg) x_{3} &= b'_{2} - \frac{a'_{23}}{a'_{33}} b'_{3} \\ a'_{31} x_{1} + a'_{32} x_{2} + a'_{33} x_{3} &= b'_{3} \\ a_{41} x_{1} + a_{42} x_{2} + a_{43} x_{3} + a_{44} x_{4} &= b_{4} \end{align*}Usando un cambio de variable
\begin{alignedat}{5} a''_{11} x_{1} & {}+{} a''_{12} x_{2} & & & {}={} b''_{1} \\ a''_{21} x_{1} & {}+{} a''_{22} x_{2} & & & {}={} b''_{2} \\ a'_{31} x_{1} & {}+{} a'_{32} x_{2} & {}+{} a'_{33} x_{3} & & {}={} b'_{3} \\ a_{41} x_{1} & {}+{} a_{42} x_{2} & {}+{} a_{43} x_{3} & {}+{} a_{44} x_{4} & {}={} b_{4} \end{alignedat}Expandiendo y agrupando términos
\begin{alignedat}{5} \bigg( a''_{11} - \frac{a''_{12}}{a''_{22}} a''_{21} \bigg) x_{1} + \bigg( a''_{12} - \frac{a''_{12}}{a''_{22}} a''_{22} \bigg) x_{2} &= b''_{1} - \frac{a''_{12}}{a''_{22}} b''_{2} \\ a''_{21} x_{1} + a''_{22} x_{2} &= b''_{2} \\ a'_{31} x_{1} + a'_{32} x_{2} + a'_{33} x_{3} &= b'_{3} \\ a_{41} x_{1} + a_{42} x_{2} + a_{43} x_{3} + a_{44} x_{4} &= b_{4} \end{alignedat}Usando un cambio de variable
\begin{alignedat}{5} a'''_{11} x_{1} & & & & {}={} b'''_{1} \\ a''_{21} x_{1} & {}+{} a''_{22} x_{2} & & & {}={} b''_{2} \\ a'_{31} x_{1} & {}+{} a'_{32} x_{2} & {}+{} a'_{33} x_{3} & & {}={} b'_{3} \\ a_{41} x_{1} & {}+{} a_{42} x_{2} & {}+{} a_{43} x_{3} & {}+{} a_{44} x_{4} & {}={} b_{4} \end{alignedat}Lo anterior puede escribirse como
\begin{equation*} \begin{array}{llll:l} a_{11} = a_{11} - \frac{a_{14}}{a_{44}} a_{41} & a_{12} = a_{12} - \frac{a_{14}}{a_{44}} a_{42} & a_{13} = a_{13} - \frac{a_{14}}{a_{44}} a_{43} & a_{14} = a_{14} - \frac{a_{14}}{a_{44}} a_{44} & b_{1} = b_{1} - \frac{a_{14}}{a_{44}} b_{4} \\ a_{21} = a_{21} - \frac{a_{24}}{a_{44}} a_{41} & a_{22} = a_{22} - \frac{a_{24}}{a_{44}} a_{42} & a_{23} = a_{23} - \frac{a_{24}}{a_{44}} a_{43} & a_{24} = a_{24} - \frac{a_{24}}{a_{44}} a_{44} & b_{2} = b_{2} - \frac{a_{24}}{a_{44}} b_{4} \\ a_{31} = a_{31} - \frac{a_{34}}{a_{44}} a_{41} & a_{32} = a_{32} - \frac{a_{34}}{a_{44}} a_{42} & a_{33} = a_{33} - \frac{a_{34}}{a_{44}} a_{43} & a_{34} = a_{34} - \frac{a_{34}}{a_{44}} a_{44} & b_{3} = b_{3} - \frac{a_{34}}{a_{44}} b_{4} \\ a_{41} = a_{41} & a_{42} = a_{42} & a_{43} = a_{43} & a_{44} = a_{44} & b_{4} = b_{4} \\ \hline a_{11} = a_{11} - \frac{a_{13}}{a_{33}} a_{31} & a_{12} = a_{12} - \frac{a_{13}}{a_{33}} a_{32} & a_{13} = a_{13} - \frac{a_{13}}{a_{33}} a_{33} & a_{14} = a_{14} - \frac{a_{13}}{a_{33}} a_{34} & b_{1} = b_{1} - \frac{a_{13}}{a_{33}} b_{3} \\ a_{21} = a_{21} - \frac{a_{23}}{a_{33}} a_{31} & a_{22} = a_{22} - \frac{a_{23}}{a_{33}} a_{32} & a_{23} = a_{23} - \frac{a_{23}}{a_{33}} a_{33} & a_{24} = a_{24} - \frac{a_{23}}{a_{33}} a_{34} & b_{2} = b_{2} - \frac{a_{23}}{a_{33}} b_{3} \\ a_{31} = a_{31} & a_{32} = a_{32} & a_{33} = a_{33} & a_{34} = a_{34} & b_{3} = b_{3} \\ a_{41} = a_{41} & a_{42} = a_{42} & a_{43} = a_{43} & a_{44} = a_{44} & b_{4} = b_{4} \\ \hline a_{11} = a_{11} - \frac{a_{12}}{a_{22}} a_{21} & a_{12} = a_{12} - \frac{a_{12}}{a_{22}} a_{22} & a_{13} = a_{13} - \frac{a_{12}}{a_{22}} a_{23} & a_{14} = a_{14} - \frac{a_{12}}{a_{22}} a_{24} & b_{1} = b_{1} - \frac{a_{12}}{a_{22}} b_{2} \\ a_{21} = a_{21} & a_{22} = a_{22} & a_{23} = a_{23} & a_{24} = a_{24} & b_{2} = b_{2} \\ a_{31} = a_{31} & a_{32} = a_{32} & a_{33} = a_{33} & a_{34} = a_{34} & b_{3} = b_{3} \\ a_{41} = a_{41} & a_{42} = a_{42} & a_{43} = a_{43} & a_{44} = a_{44} & b_{4} = b_{4} \end{array} \end{equation*}lo anterior puede escribirse como
\begin{equation*} a_{?j} = a_{?j} - \frac{a_{??}}{a_{??}} a_{?j} \end{equation*}para $j = 4, 3, 2, 1 = n , \dots, 1$
lo anterior puede escribirse como
\begin{align*} a_{ij} &= a_{ij} - \frac{a_{i?}}{a_{??}} a_{?j} \\ b_{i} &= b_{i} - \frac{a_{i?}}{a_{??}} b_{?} \end{align*}para
\begin{align*} i &= 3, 2, 1 \\ &= 2, 1 \\ &= 1 \\ \end{align*}lo anterior puede escribirse como
\begin{align*} a_{ij} &= a_{ij} - \frac{a_{ik}}{a_{kk}} a_{kj} \\ b_{i} &= b_{i} - \frac{a_{ik}}{a_{kk}} b_{k} \end{align*}para $k = 4, 3, 2 = m, \dots, 2$
function eliminacion_atras(a,b)
m, n = tamaño(a)
for k=m to 2 do
for i=k-1 to 1 do
for j=n to 1 do
a(i,j) = a(i,j) - a(i,k)*a(k,j)/a(k,k)
end for
b(i) = b(i) - a(i,k)*b(k)/a(k,k)
end for
end for
end function
otra alternativa para reducir tiempo de cálculo
function eliminacion_atras(a,b)
m, n = tamaño(a)
for k=m to 2 do
for i=k-1 to 1 do
factor = a(i,k)/a(k,k)
for j=n to 1 do
a(i,j) = a(i,j) - a(i,k)*a(k,j)/a(k,k)
end for
b(i) = b(i) - a(i,k)*b(k)/a(k,k)
end for
end for
end function
In [1]:
import numpy as np
def eliminacion_atras(A,B):
a = np.copy(A)
b = np.copy(B)
m, n = a.shape
for k in range(m-1,-1,-1):
for i in range(k-1,-1,-1):
factor = a[i,k]/a[k,k]
for j in range(n-1,-1,-1):
a[i,j] = a[i,j] - factor*a[k,j]
b[i,0] = b[i,0] - factor*b[k,0]
return a,b
In [2]:
A = np.array([[3,-0.1,-0.2],[0.1,7,-0.3],[0.3,-0.2,10]])
print(A)
In [3]:
B = np.array([7.85,-19.3,71.4]).reshape((3,1))
print(B)
In [4]:
eliminacion_atras(A,B)[0]
Out[4]:
In [5]:
eliminacion_atras(A,B)[1]
Out[5]:
Resolver el sistema de ecuaciones
\begin{equation*} \begin{bmatrix} 3.007621 & 0 & 0 \\ 0.109 & 6.994 & 0 \\ 0.3 & -0.2 & 10 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 9.022862 \\ -17.158 \\ 71.4 \end{bmatrix} \end{equation*}Incógnita $x_{1}$
\begin{equation*} x_{1} = \frac{9.022862}{3.007621} = 3 \end{equation*}Incógnita $x_{2}$
\begin{equation*} x_{2} = \frac{-17.158 - (0.109)(3)}{6.994} = -2.5 \end{equation*}Incógnita $x_{1}$
\begin{equation*} x_{1} = \frac{71.4 - (0.3)(3) - (-0.2)(-2.5)}{10} = 7 \end{equation*}Incognita $x_{1}$
\begin{equation*} x_{1} = \frac{b_{1}}{a_{11}} \end{equation*}Incognita $x_{2}$
\begin{equation*} x_{2} = \frac{b_{2} - a_{21} x_{1}}{a_{22}} \end{equation*}Incognita $x_{3}$
\begin{equation*} x_{3} = \frac{b_{3} - a_{31} x_{1} - a_{32} x_{2} }{a_{33}} \end{equation*}Incognita $x_{4}$
\begin{equation*} x_{4} = \frac{b_{4} - a_{41} x_{1} - a_{42} x_{2} - a_{43} x_{3} }{a_{44}} \end{equation*}lo anterior puede escribirse como
\begin{equation*} x_{1} = \frac{b_{1}}{a_{11}} \end{equation*}lo anterior puede escribirse como
\begin{equation*} x_{?} = \frac{b_{?} - \sum_{j}^{n} a_{?j} x_{j}}{a_{??}} \end{equation*}para
\begin{align*} j &= 1 \\ &= 1, 2 \\ &= 1, 2, 3 \end{align*}lo anterior puede escribirse como
\begin{equation*} x_{i} = \frac{b_{i} - \sum_{j}^{n} a_{ij} x_{j}}{a_{ii}} \end{equation*}para $i = 2, 3, 4 = 2, \dots, m$
function sustitucion_adelante(a,b)
m, n = tamaño(a)
x(1) = b(1)/a(1,1)
for i=2 to m do
sumatoria = b(i)
for j=1 to i-1 do
sumatoria = sumatoria - a(i,j)*x(j)
end for
x(i) = sumatoria / a(i,i)
end for
return x
end function
In [6]:
import numpy as np
def sustitucion_adelante(a,b):
m, n = a.shape
x = np.zeros(b.shape)
x[0,0] = b[0,0]/a[0,0]
for i in range(1,m):
sumatoria = b[i,0]
for j in range(0,i):
sumatoria = sumatoria - a[i,j]*x[j,0]
x[i,0] = sumatoria/a[i,i]
return x
In [7]:
A = np.array([[3.007621,0,0],
[0.109,6.994,0],
[0.3,-0.2,10]])
print(A)
In [8]:
B = np.array([[9.022862],
[-17.158],
[71.4]])
print(B)
In [9]:
sustitucion_adelante(A,B)
Out[9]:
In [10]:
#revisando el resultado
X = np.linalg.solve(A, B)
print(X)
#revisando la solución
np.allclose(np.dot(A, X), B)
Out[10]:
In [11]:
A = np.array([[1,0,0],[2,3,0],[4,5,6]])
print(A)
In [12]:
B = np.array([[7],[8],[9]])
print(B)
In [13]:
sustitucion_adelante(A,B)
Out[13]:
In [14]:
#revisando el resultado
X = np.linalg.solve(A, B)
print(X)
#revisando la solución
np.allclose(np.dot(A, X), B)
Out[14]:
In [15]:
def eliminacion_gauss(a,b):
A, B = eliminacion_atras(a,b)
x = sustitucion_adelante(A,B)
print(x)
In [16]:
C = np.array([[4,-1,1],
[2,5,2],
[1,2,4]],float)
D = np.array([[8],
[3],
[11]],float)
In [17]:
eliminacion_gauss(C,D)
In [18]:
#revisando el resultado
solucion = np.linalg.solve(C, D)
print(solucion)
#revisando la solución
np.allclose(np.dot(C, solucion), D)
Out[18]:
In [25]:
E = np.array([[1,5,-1,1,-1],
[2,2,4,-1,1],
[3,12,-3,-2,3],
[4,10,-2,4,-5],
[16,-10,6,-1,-1]],float)
F = np.array([[2],
[4],
[8],
[16],
[32]],float)
In [26]:
eliminacion_gauss(E,F)
In [27]:
#revisando el resultado
solucion = np.linalg.solve(E, F)
print(solucion)
#revisando la solución
np.allclose(np.dot(E, solucion), F)
Out[27]: