I'm trying to solve a linear system in Julia with ldlfact
. Why am I getting different results in the following cases?
Setup:
srand(10)
n = 7
pre = sprand(n,n,0.5)
H = pre + pre' + speye(n,n)
p_true = rand(n)
g = H*-p_true
fac = ldltfact(H; shift=0.0)
perm = fac[:p]
p1 = zeros(n)
p2 = zeros(n)
Case 1:
LDs = sparse(fac[:LD])
q1 = LDs\-g[perm]
p1[perm] = fac[:U]\q1
H*p - H*p_true
Case 2:
q2 = fac[:LD]\-g[perm]
p2[perm] = fac[:U]\q2
H*p2 - H*p_true
The solution p1
is wrong in the first case.