【发布时间】:2015-04-11 01:35:04
【问题描述】:
我想实现我自己的 LU 分解 P,L,U = my_lu(A),以便给定一个矩阵 A,计算带有部分旋转的 LU 分解。但我只知道如何在不旋转的情况下做到这一点。 任何人都可以帮助进行部分旋转吗?
def lu(A):
import numpy as np
# Return an error if matrix is not square
if not A.shape[0]==A.shape[1]:
raise ValueError("Input matrix must be square")
n = A.shape[0]
L = np.zeros((n,n),dtype='float64')
U = np.zeros((n,n),dtype='float64')
U[:] = A
np.fill_diagonal(L,1) # fill the diagonal of L with 1
for i in range(n-1):
for j in range(i+1,n):
L[j,i] = U[j,i]/U[i,i]
U[j,i:] = U[j,i:]-L[j,i]*U[i,i:]
U[j,i] = 0
return (L,U)
【问题讨论】:
-
在math.stackexchange.com 上问这个问题不是更充分吗?
-
LU factorization 和 LU factorization with pivoting 来自 Trefethen 和 Bau,带有清晰的伪代码
标签: python matrix decomposition