我需要创建函数[L,U] = lr(A)
,它将计算矩阵A的LU分解而不进行旋转或使用inv
,lu
等来求解线性方程。
现在尝试解决伪代码并理解它。关于如何开始的任何想法?
答案 0 :(得分:1)
# [L][U] = LUdecomp([A])
def LUdecomp(a):
n = len(a)
for k in range(0,n-1):
for i in range(k+1,n):
if a[i,k] != 0.0:
lam = a [i,k]/a[k,k]
a[i,k+1:n] = a[i,k+1:n] - lam*a[k,k+1:n]
a[i,k] = lam
return a