Los cálculos innecesarios se eliminarán para aumentar la velocidad
\begin{equation*} \begin{array}{llll} a_{11} = a_{11} & a_{12} = a_{12} & a_{13} = a_{13} & a_{14} = a_{14} \\ & a_{22} = a_{22}' & a_{23} = a_{23}' & a_{24} = a_{24}' \\ & & a_{33} = a_{33}'' & a_{34} = a_{34}'' \\ & & & a_{44} = a_{44}''' \end{array} \end{equation*}function eliminacion_adelante(a)
m, n = tamaño(a)
for k=1 to m-1 do
for i=1+k to m do
for j=1+k to n 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_adelante(a)
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+k to n do
a(i,j) = a(i,j) - factor*a(k,j)
end for
end for
end for
end function
In [1]:
import numpy as np
def eliminacion_adelante(A):
a = np.copy(A)
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(1+k,n):
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_adelante(A)
print(B)
In [4]:
np.triu(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_adelante(A)
print(B)
In [7]:
np.triu(B)
Out[7]: