# Eliminación de Gauss

Transformar el sistema de ecuaciones en un sistema triangular superior

\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*}

Primera fila pivote

\begin{equation*} \begin{bmatrix} 3 & -0.1 & -0.2 \\ 0.1 - \frac{0.1}{3} (3) & 7 - \frac{0.1}{3} (-0.1) & -0.3 - \frac{0.1}{3} (-0.2) \\ 0.3 - \frac{0.3}{3} (3) & -0.2 - \frac{0.3}{3} (-0.1) & 10 - \frac{0.3}{3} (-0.2) \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 7.85 \\ -19.3 - \frac{0.1}{3} (7.85) \\ 71.4 - \frac{0.3}{3} (7.85) \end{bmatrix} \end{equation*}

Simplificando

\begin{equation*} \begin{bmatrix} 3 & -0.1 & -0.2 \\ 0 & 7.003333 & -0.293333 \\ 0 & -0.19 & 10.02 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 7.85 \\ -19.561667 \\ 70.615 \end{bmatrix} \end{equation*}

Segunda fila pivote

\begin{equation*} \begin{bmatrix} 3 & -0.1 & -0.2 \\ 0 & 7.003333 & -0.293333 \\ 0 & -0.19 - \frac{-0.19}{7.003333} (7.003333) & 10.02 - \frac{-0.19}{7.003333} (-0.293333) \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 7.85 \\ -19.561667 \\ 70.615 - \frac{-0.19}{7.003333} (-19.561667) \end{bmatrix} \end{equation*}

Simplificando

\begin{equation*} \begin{bmatrix} 3 & -0.1 & -0.2 \\ 0 & 7.003333 & -0.293333 \\ 0 & 0 & 10.011204 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 7.85 \\ -19.561667 \\ 70.084293 \end{bmatrix} \end{equation*}

## Algoritmo 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*}

### Primera fila pivote

\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} - \frac{a_{21}}{a_{11}} ( a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} ) &= b_{2} - \frac{a_{21}}{a_{11}} b_{1} \\ a_{31} x_{1} + a_{32} x_{2} + a_{33} x_{3} + a_{34} x_{4} - \frac{a_{31}}{a_{11}} ( a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} ) &= b_{3} - \frac{a_{31}}{a_{11}} b_{1} \\ a_{41} x_{1} + a_{42} x_{2} + a_{43} x_{3} + a_{44} x_{4} - \frac{a_{41}}{a_{11}} ( a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} ) &= b_{4} - \frac{a_{41}}{a_{11}} b_{1} \end{align*}

Expandiendo y agrupando términos

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ \bigg( a_{21} - \frac{a_{21}}{a_{11}} a_{11} \bigg) x_{1} + \bigg( a_{22} - \frac{a_{21}}{a_{11}} a_{12} \bigg) x_{2} + \bigg( a_{23} - \frac{a_{21}}{a_{11}} a_{13} \bigg) x_{3} + \bigg( a_{24} - \frac{a_{21}}{a_{11}} a_{14} \bigg) x_{4} &= b_{2} - \frac{a_{21}}{a_{11}} b_{1} \\ \bigg( a_{31} - \frac{a_{31}}{a_{11}} a_{11} \bigg) x_{1} + \bigg( a_{32} - \frac{a_{31}}{a_{11}} a_{12} \bigg) x_{2} + \bigg( a_{33} - \frac{a_{21}}{a_{11}} a_{13} \bigg) x_{3} + \bigg( a_{34} - \frac{a_{21}}{a_{11}} a_{14} \bigg) x_{4} &= b_{3} - \frac{a_{31}}{a_{11}} b_{1} \\ \bigg( a_{41} - \frac{a_{41}}{a_{11}} a_{11} \bigg) x_{1} + \bigg( a_{42} - \frac{a_{41}}{a_{11}} a_{12} \bigg) x_{2} + \bigg( a_{43} - \frac{a_{21}}{a_{11}} a_{13} \bigg) x_{3} + \bigg( a_{44} - \frac{a_{21}}{a_{11}} a_{14} \bigg) x_{4} &= b_{4} - \frac{a_{41}}{a_{11}} b_{1} \end{align*}

Usando un cambio de variable

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} &= b'_{2} \\ a'_{32} x_{2} + a'_{33} x_{3} + a'_{34} x_{4} &= b'_{3} \\ a'_{42} x_{2} + a'_{43} x_{3} + a'_{44} x_{4} &= b'_{4} \end{align*}

### Segunda fila pivote

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} &= b'_{2} \\ a'_{32} x_{2} + a'_{33} x_{3} + a'_{34} x_{4} - \frac{a'_{32}}{a'_{22}} ( a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} ) &= b'_{3} - \frac{a'_{32}}{a'_{22}} b'_{2} \\ a'_{42} x_{2} + a'_{43} x_{3} + a'_{44} x_{4} - \frac{a'_{42}}{a'_{22}} ( a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} ) &= b'_{4} - \frac{a'_{42}}{a'_{22}} b'_{2} \end{align*}

Expandiendo y agrupando términos

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} &= b'_{2} \\ \bigg( a'_{32} - \frac{a'_{32}}{a'_{22}} a'_{22} \bigg) x_{2} + \bigg( a'_{33} - \frac{a'_{32}}{a'_{22}} a'_{23} \bigg) x_{3} + \bigg( a'_{34} - \frac{a'_{32}}{a'_{22}} a'_{24} \bigg) x_{4} &= b'_{3} - \frac{a'_{32}}{a'_{22}} b'_{2} \\ \bigg( a'_{42} - \frac{a'_{42}}{a'_{22}} a'_{22} \bigg) x_{2} + \bigg( a'_{43} - \frac{a'_{42}}{a'_{22}} a'_{23} \bigg) x_{3} + \bigg( a'_{44} - \frac{a'_{42}}{a'_{22}} a'_{24} \bigg) x_{4} &= b'_{4} - \frac{a'_{42}}{a'_{22}} b'_{2} \end{align*}

Usando un cambio de variable

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} &= b'_{2} \\ a''_{33} x_{3} + a''_{34} x_{4} &= b''_{3} \\ a''_{43} x_{3} + a''_{44} x_{4} &= b''_{4} \end{align*}

### Tercera fila pivote

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} &= b'_{2} \\ a''_{33} x_{3} + a''_{34} x_{4} &= b''_{3} \\ a''_{43} x_{3} + a''_{44} x_{4} - \frac{a''_{43}}{a''_{33}} ( a''_{33} x_{3} + a''_{34} x_{4} )&= b''_{4} - \frac{a''_{43}}{a''_{33}} b''_{3} \end{align*}

Expandiendo y agrupando términos

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} &= b'_{2} \\ a''_{33} x_{3} + a''_{34} x_{4} &= b''_{3} \\ \bigg( a''_{43} - \frac{a''_{43}}{a''_{33}} a''_{33} \bigg) x_{3} + \bigg( a''_{44} - \frac{a''_{43}}{a''_{33}} a''_{34} \bigg) x_{4} &= b''_{4} - \frac{a''_{43}}{a''_{33}} b''_{3} \end{align*}

Usando un cambio de variable

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a'_{22} x_{2} + a'_{23} x_{3} + a'_{24} x_{4} &= b'_{2} \\ a''_{33} x_{3} + a''_{34} x_{4} &= b''_{3} \\ a'''_{44} x_{4} &= b'''_{4} \end{align*}

Lo anterior puede escribirse como

\begin{equation*} \begin{array}{llll:l} a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{21} = a_{21} - \frac{a_{21}}{a_{11}} a_{11} & a_{22} = a_{22} - \frac{a_{21}}{a_{11}} a_{12} & a_{23} = a_{23} - \frac{a_{21}}{a_{11}} a_{13} & a_{24} = a_{24} - \frac{a_{21}}{a_{11}} a_{14} & b_{2} = b_{2} - \frac{a_{21}}{a_{11}} b_{1} \\ a_{31} = a_{31} - \frac{a_{31}}{a_{11}} a_{11} & a_{32} = a_{32} - \frac{a_{31}}{a_{11}} a_{12} & a_{33} = a_{33} - \frac{a_{31}}{a_{11}} a_{13} & a_{34} = a_{34} - \frac{a_{31}}{a_{11}} a_{14} & b_{3} = b_{3} - \frac{a_{31}}{a_{11}} b_{1} \\ a_{41} = a_{41} - \frac{a_{41}}{a_{11}} a_{11} & a_{42} = a_{42} - \frac{a_{41}}{a_{11}} a_{12} & a_{43} = a_{43} - \frac{a_{41}}{a_{11}} a_{13} & a_{44} = a_{44} - \frac{a_{41}}{a_{11}} a_{14} & b_{4} = b_{4} - \frac{a_{41}}{a_{11}} b_{1} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{21} = a_{21} & a_{22} = a_{22} & a_{23} = a_{23} & a_{24} = a_{24} & b_{2} = b_{2} \\ a_{31} = a_{31} - \frac{a_{32}}{a_{22}} a_{21} & a_{32} = a_{32} - \frac{a_{32}}{a_{22}} a_{22} & a_{33} = a_{33} - \frac{a_{32}}{a_{22}} a_{23} & a_{34} = a_{34} - \frac{a_{32}}{a_{22}} a_{24} & b_{3} = b_{3} - \frac{a_{32}}{a_{22}} b_{2} \\ a_{41} = a_{41} - \frac{a_{42}}{a_{22}} a_{21} & a_{42} = a_{42} - \frac{a_{42}}{a_{22}} a_{22} & a_{43} = a_{43} - \frac{a_{42}}{a_{22}} a_{23} & a_{44} = a_{44} - \frac{a_{42}}{a_{22}} a_{24} & b_{4} = b_{4} - \frac{a_{42}}{a_{22}} b_{2} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ 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} - \frac{a_{43}}{a_{33}} a_{31} & a_{42} = a_{42} - \frac{a_{43}}{a_{33}} a_{32} & a_{43} = a_{43} - \frac{a_{43}}{a_{33}} a_{33} & a_{44} = a_{44} - \frac{a_{43}}{a_{33}} a_{34} & b_{4} = b_{4} - \frac{a_{43}}{a_{33}} b_{3} \end{array} \end{equation*}

## Patrón de cálculo

### Primer patrón

\begin{equation*} \begin{array}{llll:l} a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{2\color{blue}{1}} = a_{2\color{blue}{1}} - \frac{a_{21}}{a_{11}} a_{1\color{blue}{1}} & a_{2\color{green}{2}} = a_{2\color{green}{2}} - \frac{a_{21}}{a_{11}} a_{1\color{green}{2}} & a_{2\color{red}{3}} = a_{2\color{red}{3}} - \frac{a_{21}}{a_{11}} a_{1\color{red}{3}} & a_{2\color{fuchsia}{4}} = a_{2\color{fuchsia}{4}} - \frac{a_{21}}{a_{11}} a_{1\color{fuchsia}{4}} & b_{2} = b_{2} - \frac{a_{21}}{a_{11}} b_{1} \\ a_{3\color{blue}{1}} = a_{3\color{blue}{1}} - \frac{a_{31}}{a_{11}} a_{1\color{blue}{1}} & a_{3\color{green}{2}} = a_{3\color{green}{2}} - \frac{a_{31}}{a_{11}} a_{1\color{green}{2}} & a_{3\color{red}{3}} = a_{3\color{red}{3}} - \frac{a_{31}}{a_{11}} a_{1\color{red}{3}} & a_{3\color{fuchsia}{4}} = a_{3\color{fuchsia}{4}} - \frac{a_{31}}{a_{11}} a_{1\color{fuchsia}{4}} & b_{3} = b_{3} - \frac{a_{31}}{a_{11}} b_{1} \\ a_{4\color{blue}{1}} = a_{4\color{blue}{1}} - \frac{a_{41}}{a_{11}} a_{1\color{blue}{1}} & a_{4\color{green}{2}} = a_{4\color{green}{2}} - \frac{a_{41}}{a_{11}} a_{1\color{green}{2}} & a_{4\color{red}{3}} = a_{4\color{red}{3}} - \frac{a_{41}}{a_{11}} a_{1\color{red}{3}} & a_{4\color{fuchsia}{4}} = a_{4\color{fuchsia}{4}} - \frac{a_{41}}{a_{11}} a_{1\color{fuchsia}{4}} & b_{4} = b_{4} - \frac{a_{41}}{a_{11}} b_{1} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{21} = a_{21} & a_{22} = a_{22} & a_{23} = a_{23} & a_{24} = a_{24} & b_{2} = b_{2} \\ a_{3\color{blue}{1}} = a_{3\color{blue}{1}} - \frac{a_{32}}{a_{22}} a_{2\color{blue}{1}} & a_{3\color{green}{2}} = a_{3\color{green}{2}} - \frac{a_{32}}{a_{22}} a_{2\color{green}{2}} & a_{3\color{red}{3}} = a_{3\color{red}{3}} - \frac{a_{32}}{a_{22}} a_{2\color{red}{3}} & a_{3\color{fuchsia}{4}} = a_{3\color{fuchsia}{4}} - \frac{a_{32}}{a_{22}} a_{2\color{fuchsia}{4}} & b_{3} = b_{3} - \frac{a_{32}}{a_{22}} b_{2} \\ a_{4\color{blue}{1}} = a_{4\color{blue}{1}} - \frac{a_{42}}{a_{22}} a_{2\color{blue}{1}} & a_{4\color{green}{2}} = a_{4\color{green}{2}} - \frac{a_{42}}{a_{22}} a_{2\color{green}{2}} & a_{4\color{red}{3}} = a_{4\color{red}{3}} - \frac{a_{42}}{a_{22}} a_{2\color{red}{3}} & a_{4\color{fuchsia}{4}} = a_{4\color{fuchsia}{4}} - \frac{a_{42}}{a_{22}} a_{2\color{fuchsia}{4}} & b_{4} = b_{4} - \frac{a_{42}}{a_{22}} b_{2} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ 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_{4\color{blue}{1}} = a_{4\color{blue}{1}} - \frac{a_{43}}{a_{33}} a_{3\color{blue}{1}} & a_{4\color{green}{2}} = a_{4\color{green}{2}} - \frac{a_{43}}{a_{33}} a_{3\color{green}{2}} & a_{4\color{red}{3}} = a_{4\color{red}{3}} - \frac{a_{43}}{a_{33}} a_{3\color{red}{3}} & a_{4\color{fuchsia}{4}} = a_{4\color{fuchsia}{4}} - \frac{a_{43}}{a_{33}} a_{3\color{fuchsia}{4}} & b_{4} = b_{4} - \frac{a_{43}}{a_{33}} b_{3} \end{array} \end{equation*}

lo anterior puede escribirse como

\begin{equation*} a_{?j} = a_{?j} - \frac{a_{??}}{a_{??}} a_{?j} \end{equation*}

para $j = 1, 2, 3, 4 = 1 , \dots, n$

### Segundo patrón

\begin{equation*} \begin{array}{llll:l} a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{\color{blue}{2}1} = a_{\color{blue}{2}1} - \frac{a_{\color{blue}{2}1}}{a_{11}} a_{11} & a_{\color{blue}{2}2} = a_{\color{blue}{2}2} - \frac{a_{\color{blue}{2}1}}{a_{11}} a_{12} & a_{\color{blue}{2}3} = a_{\color{blue}{2}3} - \frac{a_{\color{blue}{2}1}}{a_{11}} a_{13} & a_{\color{blue}{2}4} = a_{\color{blue}{2}4} - \frac{a_{\color{blue}{2}1}}{a_{11}} a_{14} & b_{\color{blue}{2}} = b_{\color{blue}{2}} - \frac{a_{\color{blue}{2}1}}{a_{11}} b_{1} \\ a_{\color{green}{3}1} = a_{\color{green}{3}1} - \frac{a_{\color{green}{3}1}}{a_{11}} a_{11} & a_{\color{green}{3}2} = a_{\color{green}{3}2} - \frac{a_{\color{green}{3}1}}{a_{11}} a_{12} & a_{\color{green}{3}3} = a_{\color{green}{3}3} - \frac{a_{\color{green}{3}1}}{a_{11}} a_{13} & a_{\color{green}{3}4} = a_{\color{green}{3}4} - \frac{a_{\color{green}{3}1}}{a_{11}} a_{14} & b_{\color{green}{3}} = b_{\color{green}{3}} - \frac{a_{\color{green}{3}1}}{a_{11}} b_{1} \\ a_{\color{red}{4}1} = a_{\color{red}{4}1} - \frac{a_{\color{red}{4}1}}{a_{11}} a_{11} & a_{\color{red}{4}2} = a_{\color{red}{4}2} - \frac{a_{\color{red}{4}1}}{a_{11}} a_{12} & a_{\color{red}{4}3} = a_{\color{red}{4}3} - \frac{a_{\color{red}{4}1}}{a_{11}} a_{13} & a_{\color{red}{4}4} = a_{\color{red}{4}4} - \frac{a_{\color{red}{4}1}}{a_{11}} a_{14} & b_{\color{red}{4}} = b_{\color{red}{4}} - \frac{a_{\color{red}{4}1}}{a_{11}} b_{1} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{21} = a_{21} & a_{22} = a_{22} & a_{23} = a_{23} & a_{24} = a_{24} & b_{2} = b_{2} \\ a_{\color{green}{3}1} = a_{\color{green}{3}1} - \frac{a_{\color{green}{3}2}}{a_{22}} a_{21} & a_{\color{green}{3}2} = a_{\color{green}{3}2} - \frac{a_{\color{green}{3}2}}{a_{22}} a_{22} & a_{\color{green}{3}3} = a_{\color{green}{3}3} - \frac{a_{\color{green}{3}2}}{a_{22}} a_{23} & a_{\color{green}{3}4} = a_{\color{green}{3}4} - \frac{a_{\color{green}{3}2}}{a_{22}} a_{24} & b_{\color{green}{3}} = b_{\color{green}{3}} - \frac{a_{\color{green}{3}2}}{a_{22}} b_{2} \\ a_{\color{red}{4}1} = a_{\color{red}{4}1} - \frac{a_{\color{red}{4}2}}{a_{22}} a_{21} & a_{\color{red}{4}2} = a_{\color{red}{4}2} - \frac{a_{\color{red}{4}2}}{a_{22}} a_{22} & a_{\color{red}{4}3} = a_{\color{red}{4}3} - \frac{a_{\color{red}{4}2}}{a_{22}} a_{23} & a_{\color{red}{4}4} = a_{\color{red}{4}4} - \frac{a_{\color{red}{4}2}}{a_{22}} a_{24} & b_{\color{red}{4}} = b_{\color{red}{4}} - \frac{a_{\color{red}{4}2}}{a_{22}} b_{2} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ 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_{\color{red}{4}1} = a_{\color{red}{4}1} - \frac{a_{\color{red}{4}3}}{a_{33}} a_{31} & a_{\color{red}{4}2} = a_{\color{red}{4}2} - \frac{a_{\color{red}{4}3}}{a_{33}} a_{32} & a_{\color{red}{4}3} = a_{\color{red}{4}3} - \frac{a_{\color{red}{4}3}}{a_{33}} a_{33} & a_{\color{red}{4}4} = a_{\color{red}{4}4} - \frac{a_{\color{red}{4}3}}{a_{33}} a_{34} & b_{\color{red}{4}} = b_{\color{red}{4}} - \frac{a_{\color{red}{4}3}}{a_{33}} b_{3} \end{array} \end{equation*}

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 &= 2, 3, 4 = 2, \dots, m \\ &= 3, 4 = 3, \dots, m \\ &= 4 = 4 , \dots, m \end{align*}

### Tercer patrón

\begin{equation*} \begin{array}{llll:l} a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{21} = a_{21} - \frac{a_{2\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}1} & a_{22} = a_{22} - \frac{a_{2\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}2} & a_{23} = a_{23} - \frac{a_{2\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}3} & a_{24} = a_{24} - \frac{a_{2\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}4} & b_{2} = b_{2} - \frac{a_{2\color{blue}{1}}}{a_{\color{blue}{11}}} b_{\color{blue}{1}} \\ a_{31} = a_{31} - \frac{a_{3\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}1} & a_{32} = a_{32} - \frac{a_{3\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}2} & a_{33} = a_{33} - \frac{a_{3\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}3} & a_{34} = a_{34} - \frac{a_{3\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}4} & b_{3} = b_{3} - \frac{a_{3\color{blue}{1}}}{a_{\color{blue}{11}}} b_{\color{blue}{1}} \\ a_{41} = a_{41} - \frac{a_{4\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}1} & a_{42} = a_{42} - \frac{a_{4\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}2} & a_{43} = a_{43} - \frac{a_{4\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}3} & a_{44} = a_{44} - \frac{a_{4\color{blue}{1}}}{a_{\color{blue}{11}}} a_{\color{blue}{1}4} & b_{4} = b_{4} - \frac{a_{4\color{blue}{1}}}{a_{\color{blue}{11}}} b_{\color{blue}{1}} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ a_{21} = a_{21} & a_{22} = a_{22} & a_{23} = a_{23} & a_{24} = a_{24} & b_{2} = b_{2} \\ a_{31} = a_{31} - \frac{a_{3\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}1} & a_{32} = a_{32} - \frac{a_{3\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}2} & a_{33} = a_{33} - \frac{a_{3\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}3} & a_{34} = a_{34} - \frac{a_{3\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}4} & b_{3} = b_{3} - \frac{a_{3\color{green}{2}}}{a_{\color{green}{22}}} b_{\color{green}{2}} \\ a_{41} = a_{41} - \frac{a_{4\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}1} & a_{42} = a_{42} - \frac{a_{4\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}2} & a_{43} = a_{43} - \frac{a_{4\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}3} & a_{44} = a_{44} - \frac{a_{4\color{green}{2}}}{a_{\color{green}{22}}} a_{\color{green}{2}4} & b_{4} = b_{4} - \frac{a_{4\color{green}{2}}}{a_{\color{green}{22}}} b_{\color{green}{2}} \\ \hline a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} & b_{1} = b_{1} \\ 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} - \frac{a_{4\color{red}{3}}}{a_{\color{red}{33}}} a_{\color{red}{3}1} & a_{42} = a_{42} - \frac{a_{4\color{red}{3}}}{a_{\color{red}{33}}} a_{\color{red}{3}2} & a_{43} = a_{43} - \frac{a_{4\color{red}{3}}}{a_{\color{red}{33}}} a_{\color{red}{3}3} & a_{44} = a_{44} - \frac{a_{4\color{red}{3}}}{a_{\color{red}{33}}} a_{\color{red}{3}4} & b_{4} = b_{4} - \frac{a_{4\color{red}{3}}}{a_{\color{red}{33}}} b_{\color{red}{3}} \end{array} \end{equation*}

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 = 1, 2, 3 = 1, \dots, m - 1$

### Fórmula matemática

\begin{align*} k &= 1, \dots, m - 1 \\ & \quad i = 1 + k, \dots, m \\ & \quad \quad j = 1, \dots, n \\ & \quad \quad \quad a_{ij} = a_{ij} - \frac{a_{ik}}{a_{kk}} a_{kj} \\ & \quad \quad b_{i} = b_{i} - \frac{a_{ik}}{a_{kk}} b_{k} \end{align*}

## Seudocódigo

function eliminacion_adelante(a,b)
m, n = tamaño(a)
for k=1 to m-1 do
for i=1+k to m do
for j=1 to n 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_adelante(a,b)
m, n = tamaño(a)
for k=1 to m-1 do
for i=1+k to m do
factor = a(i,k)/a(k,k)
for j=1 to n do
a(i,j) = a(i,j) - factor*a(k,j)
end for
b(i) = b(i) - factor*b(k)
end for
end for
end function




In [1]:

import numpy as np

a = np.copy(A)
b = np.copy(B)
m, n = a.shape
for k in range(0,m-1):
for i in range(1+k,m):
factor = a[i,k]/a[k,k]
for j in range(0,n):
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)




[[  3.   -0.1  -0.2]
[  0.1   7.   -0.3]
[  0.3  -0.2  10. ]]




In [3]:

B = np.array([7.85,-19.3,71.4]).reshape((3,1))
print(B)




[[  7.85]
[-19.3 ]
[ 71.4 ]]




In [4]:




Out[4]:

array([[  3.        ,  -0.1       ,  -0.2       ],
[  0.        ,   7.00333333,  -0.29333333],
[  0.        ,   0.        ,  10.01204188]])




In [5]:




Out[5]:

array([[  7.85      ],
[-19.56166667],
[ 70.08429319]])




In [6]:

#revisando
from scipy.linalg import lu
p, l, u = lu(np.concatenate((A,B),axis=1), permute_l=False, overwrite_a=False, check_finite=True)
print(u)




[[  3.          -0.1         -0.2          7.85      ]
[  0.           7.00333333  -0.29333333 -19.56166667]
[  0.           0.          10.01204188  70.08429319]]



## Sustitución hacia atrás

Resolver el sistema de ecuaciones

\begin{equation*} \begin{bmatrix} 3 & -0.1 & -0.2 \\ 0 & 7.003333 & -0.293333 \\ 0 & 0 & 10.011204 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{bmatrix} = \begin{bmatrix} 7.85 \\ -19.561667 \\ 70.084293 \end{bmatrix} \end{equation*}

Incógnita $x_{3}$

\begin{equation*} x_{3} = \frac{70.084293}{10.011204} = 7.000586 \end{equation*}

Incógnita $x_{2}$

\begin{equation*} x_{2} = \frac{-19.561667 - (-0.293333)(7.000586)}{7.003333} = -2.499976 \end{equation*}

Incógnita $x_{1}$

\begin{equation*} x_{1} = \frac{7.85 - (-0.1)(-2.499976) - (-0.2)(7.000586)}{3} = 3.000040 \end{equation*}

## Algoritmo de cálculo

\begin{align*} a_{11} x_{1} + a_{12} x_{2} + a_{13} x_{3} + a_{14} x_{4} &= b_{1} \\ a_{22} x_{2} + a_{23} x_{3} + a_{24} x_{4} &= b_{2} \\ a_{33} x_{3} + a_{34} x_{4} &= b_{3} \\ a_{44} x_{4} &= b_{4} \end{align*}

Incognita $x_{4}$

\begin{equation*} x_{4} = \frac{b_{4}}{a_{44}} \end{equation*}

Incognita $x_{3}$

\begin{equation*} x_{3} = \frac{b_{3} - a_{34} x_{4}}{a_{33}} \end{equation*}

Incognita $x_{2}$

\begin{equation*} x_{2} = \frac{b_{2} - a_{23} x_{3} - a_{24} x_{4} }{a_{22}} \end{equation*}

Incognita $x_{1}$

\begin{equation*} x_{1} = \frac{b_{1} - a_{12} x_{2} - a_{13} x_{3} - a_{14} x_{4} }{a_{11}} \end{equation*}

## Patrón de cálculo

### Primer patrón

\begin{align*} x_{\color{blue}{4}} &= \frac{b_{\color{blue}{4}}}{a_{\color{blue}{44}}} \\ x_{3} &= \frac{b_{3} - a_{34} x_{4}}{a_{33}} \\ x_{2} &= \frac{b_{2} - a_{23} x_{3} - a_{24} x_{4} }{a_{22}} \\ x_{1} &= \frac{b_{1} - a_{12} x_{2} - a_{13} x_{3} - a_{14} x_{4} }{a_{11}} \end{align*}

lo anterior puede escribirse como

\begin{equation*} x_{m} = \frac{b_{m}}{a_{mm}} \end{equation*}

### Segundo patrón

\begin{align*} x_{4} &= \frac{b_{4}}{a_{44}} \\ x_{3} &= \frac{b_{3} - a_{3\color{blue}{4}} x_{\color{blue}{4}}}{a_{33}} \\ x_{2} &= \frac{b_{2} - a_{2\color{green}{3}} x_{\color{green}{3}} - a_{2\color{blue}{4}} x_{\color{blue}{4}} }{a_{22}} \\ x_{1} &= \frac{b_{1} - a_{1\color{red}{2}} x_{\color{red}{2}} - a_{1\color{green}{3}} x_{\color{green}{3}} - a_{1\color{blue}{4}} x_{\color{blue}{4}} }{a_{11}} \end{align*}

lo anterior puede escribirse como

\begin{equation*} x_{?} = \frac{b_{?} - \sum_{n}^{j} a_{?j} x_{j}}{a_{??}} \end{equation*}

para

\begin{align*} j &= 4 = n, \dots, 4 \\ &= 4, 3 = n, \dots, 3 \\ &= 4, 3, 2 = n, \dots, 2 \end{align*}

### Tercer patrón

\begin{align*} x_{4} &= \frac{b_{4}}{a_{44}} \\ x_{\color{blue}{3}} &= \frac{b_{\color{blue}{3}} - a_{\color{blue}{3}4} x_{4}}{a_{\color{blue}{33}}} \\ x_{\color{green}{2}} &= \frac{b_{\color{green}{2}} - a_{\color{green}{2}3} x_{3} - a_{\color{green}{2}4} x_{4} }{a_{\color{green}{22}}} \\ x_{\color{red}{1}} &= \frac{b_{\color{red}{1}} - a_{\color{red}{1}2} x_{2} - a_{\color{red}{1}3} x_{3} - a_{\color{red}{1}4} x_{4} }{a_{\color{red}{11}}} \end{align*}

lo anterior puede escribirse como

\begin{equation*} x_{i} = \frac{b_{i} - \sum_{n}^{j} a_{ij} x_{j}}{a_{ii}} \end{equation*}

para $i = 3, 2, 1 = m - 1, \dots, 1$

## Fórmula matemática

\begin{align*} x_{m} &= \frac{b_{m}}{a_{mm}} \\ i &= m - 1, \dots, 1 \\ & \quad x_{i} = \frac{b_{i} - \sum_{j=n}^{1+i} a_{ij} x_{j}}{a_{ii}} \end{align*}

## Seudocódigo

function sustitucion_atras(a,b)
m, n = tamaño(a)
x(m) = b(m)/a(m,m)
for i=m-1 to 1 do
sumatoria = b(i)
for j=n to 1+i do
sumatoria = sumatoria - a(i,j)*x(j)
end for
x(i) = sumatoria / a(i,i)
end for
return x
end function


## Implementación sustitución hacia atrás



In [7]:

import numpy as np

def sustitucion_atras(a,b):
m, n = a.shape
x = np.zeros(b.shape)
x[m-1,0] = b[m-1,0]/a[m-1,m-1]
for i in range(m-2,-1,-1):
sumatoria = b[i,0]
for j in range(n-1,i,-1):
sumatoria = sumatoria - a[i,j]*x[j,0]
x[i,0] = sumatoria/a[i,i]
return x




In [8]:

A = np.array([[3,-0.1,-0.2],[0,7.003333,-0.293333],[0,0,10.011204]])
print(A)




[[  3.        -0.1       -0.2     ]
[  0.         7.003333  -0.293333]
[  0.         0.        10.011204]]




In [9]:

B = np.array([[7.85],[-19.561667],[70.084293]])
print(B)




[[  7.85    ]
[-19.561667]
[ 70.084293]]




In [10]:

sustitucion_atras(A,B)




Out[10]:

array([[ 3.00003986],
[-2.49997596],
[ 7.00058584]])




In [11]:

X = np.linalg.solve(A, B)
print(X)
#revisando la solución
np.allclose(np.dot(A, X), B)




[[ 3.00003986]
[-2.49997596]
[ 7.00058584]]

Out[11]:

True




In [12]:

A = np.array([[1,2,3],[0,4,5],[0,0,6]],float)
print(A)




[[ 1.  2.  3.]
[ 0.  4.  5.]
[ 0.  0.  6.]]




In [13]:

B = np.array([[7],[8],[9]],float)
print(B)




[[ 7.]
[ 8.]
[ 9.]]




In [14]:

sustitucion_atras(A,B)




Out[14]:

array([[ 2.25 ],
[ 0.125],
[ 1.5  ]])




In [15]:

X = np.linalg.solve(A, B)
print(X)
#revisando la solución
np.allclose(np.dot(A, X), B)




[[ 2.25 ]
[ 0.125]
[ 1.5  ]]

Out[15]:

True



# Implementación eliminación de Gauss



In [16]:

def eliminacion_gauss(a,b):
x = sustitucion_atras(A,B)
print(x)




In [17]:

A = np.array([[3,-0.1,-0.2],[0.1,7,-0.3],[0.3,-0.2,10]])
print(A)




[[  3.   -0.1  -0.2]
[  0.1   7.   -0.3]
[  0.3  -0.2  10. ]]




In [18]:

B = np.array([7.85,-19.3,71.4]).reshape((3,1))
print(B)




[[  7.85]
[-19.3 ]
[ 71.4 ]]




In [19]:

eliminacion_gauss(A,B)




[[ 3. ]
[-2.5]
[ 7. ]]




In [20]:

solucion = np.linalg.solve(A, B)
print(solucion)
#revisando la solución
np.allclose(np.dot(A, solucion), B)




[[ 3. ]
[-2.5]
[ 7. ]]

Out[20]:

True




In [21]:

C = np.array([[4,-1,1],
[2,5,2],
[1,2,4]],float)
D = np.array([[8],
[3],
[11]],float)




In [22]:

eliminacion_gauss(C,D)




[[ 1.]
[-1.]
[ 3.]]




In [23]:

solucion = np.linalg.solve(C, D)
print(solucion)
#revisando la solución
np.allclose(np.dot(C, solucion), D)




[[ 1.]
[-1.]
[ 3.]]

Out[23]:

True




In [24]:

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 [25]:

eliminacion_gauss(E,F)




[[ -0.125     ]
[  1.42105263]
[ -1.19078947]
[-30.76315789]
[-24.59210526]]




In [26]:

solucion = np.linalg.solve(E, F)
print(solucion)
#revisando la solución
np.allclose(np.dot(E, solucion), F)




[[ -0.125     ]
[  1.42105263]
[ -1.19078947]
[-30.76315789]
[-24.59210526]]

Out[26]:

True