python - LU decomposition with pivoting in numpy -


i can't find what's wrong attempt @ implementing lu decomposition partial pivoting pseudo-code here (page 6). code pasted below. can spot problem?

def lupdecomposition(matrix): n, m = matrix.shape assert n == m, "lu decomposition applicable square matrices" l = np.identity(n) u = matrix.copy() p = np.identity(n)  k in range(n-1):      # pivoting: index of maximum in k-th column on diagonal or below     index = np.argmax(abs(u[k:,k]))     index += k      # pivoting: permute rows     if index != k:         u[[index,k],k:n] = u[[k,index],k:n]         p[[index,k]] = p[[k,index]]         if index > 0:             l[[index,k],0:(k-1)] = l[[k,index],0:(k-1)]      # calculating next column in l , modifing rows in u     j in range(k+1,n):         l[j,k] = u[j,k] / u[k,k]         u[j,k:] -= l[j,k]*u[k,k:]  return l,u,p 


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -