更新时间:2023-12-01 09:47:58
提取ldltfact
的相关分解矩阵可能有点乏味.下面的示例显示了一个与问题中的示例相似的示例,并进行了最终测试,即提取的矩阵将恢复原始的因式分解后的矩阵:
Extracting the relevant factorization matrices of ldltfact
can be a little tedious. The following example shows an example similar to the one in the question with a final test that the extracted matrices recover the original factorized one:
srand(1)
pre = sprand(10,10,0.5)
H = pre + pre' + speye(10,10)
fac = ldltfact(H; shift=0.0)
P = sparse(1:size(H,1),fac[:p],ones(size(H,1)))
LD = sparse(fac[:LD]) # this matrix contains both D and L embedded in it
L = copy(LD)
for i=1:size(L,1)
L[i,i] = 1.0
end
D = sparse(1:size(L,1),1:size(L,1),diag(LD))
PHP = P*H*P'
LDL = L*D*L'
using Base.Test
@test PHP ≈ LDL
预期的输出(在Julia v0.6.3上是实际的):
The expected output (and actual on Julia v0.6.3):
julia> @test PHP ≈ LDL
Test Passed
希望这会有所帮助.