Los cálculos innecesarios se eliminarán para aumentar la velocidad
\begin{equation*} \begin{array}{llll} a_{11} = a'''_{11} & & & \\ a_{21} = a''_{21} & a_{22} = a''_{22} & & \\ a_{31} = a'_{31} & a_{32} = a'_{32} & a_{33} = a'_{33} & \\ a_{41} = a_{41} & a_{42} = a_{42} & a_{43} = a_{43} & a_{44} = a_{44} \end{array} \end{equation*}function eliminacion_atras(a)
m, n = tamaño(a)
for k=m to 2 do
for i=k-1 to 1 do
for j=k-1 to 1 do
a(i,j) = a(i,j) - a(i,k)*a(k,j)/a(k,k)
end for
end for
end for
end function
otra alternativa para reducir tiempo de cálculo
function eliminacion_atras(a)
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=k-1 to 1 do
a(i,j) = a(i,j) - a(i,k)*a(k,j)/a(k,k)
end for
end for
end for
end function
In [1]:
import numpy as np
def eliminacion_atras(A):
a = np.copy(A)
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(k-1,-1,-1):
a[i,j] = a[i,j] - factor*a[k,j]
return a
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 = eliminacion_atras(A)
print(B)
In [4]:
np.tril(B)
Out[4]:
In [5]:
A = np.array([[1,1,2,3],
[2,1,-1,1],
[3,-1,-1,2],
[-1,2,3,-1]],float)
print(A)
In [6]:
B = eliminacion_atras(A)
print(B)
In [7]:
np.tril(B)
Out[7]: