【发布时间】:2018-05-28 11:38:00
【问题描述】:
我正在阅读 Saul I. Gass 的第 5 版线性规划。
他给出了以下文本和示例: “给定一个nxn非奇异矩阵A,那么A可以表示为乘积A = LU... ...如果我们让U(或L)的对角元素都等于1,那么LU分解将是唯一的。 ..”
我设法用我从这个 SO 问题中找到的这段代码进行了可逆的上下分解:Is there a built-in/easy LDU decomposition method in Numpy?
但我仍然不知道发生了什么,为什么L和U与我的教科书如此不同。谁能给我解释一下?
所以这段代码:
import numpy as np
import scipy.linalg as la
a = np.array([[1, 1, -1],
[-2, 1, 1],
[1, 1, 1]])
(P, L, U) = la.lu(a)
print(P)
print(L)
print(U)
D = np.diag(np.diag(U)) # D is just the diagonal of U
U /= np.diag(U)[:, None] # Normalize rows of U
print(P.dot(L.dot(D.dot(U)))) # Check
给出这个输出:
[[ 0. 1. 0.]
[ 1. 0. 0.]
[ 0. 0. 1.]]
[[ 1. 0. 0. ]
[-0.5 1. 0. ]
[-0.5 1. 1. ]]
[[-2. 1. 1. ]
[ 0. 1.5 -0.5]
[ 0. 0. 2. ]]
[[ 1. 1. -1.]
[-2. 1. 1.]
[ 1. 1. 1.]]
【问题讨论】:
-
你的教科书没有遵循惯例。
标签: python numpy math matrix scipy