COMPUTER PROBLEMS 2.2
1 The elimination part of the code must be supplemented by
filling in the entries of \(L\) and \(U\). The diagonal entries of \(L\)
are ones, and the remaining entries are the multipliers from mult.
It is also necessary to change the k loop to go from
j to n, in order to place a zero in the eliminated
location of \(U\). Python code follows:
import numpy as np
def my_lu(a):
n,_ = a.shape
l = np.identity(n)
for j in range(n-1):
if np.abs(a[j,j]) < np.finfo(np.float64).eps:
raise ValueError('zero pivot encountered')
for i in range(j+1,n):
mult = a[i,j]/a[j,j]
l[i,j] = mult
for k in range(j+1,n):
a[i,k] = a[i,k] - mult*a[j,k]
u = np.triu(a)
return l,u