Chapter 2

f_02_04.jl

Cholesky LLt factorization using banded storage

Other versions: j_02_04.jl, nm24.jl


In [12]:
using NMfE

In [13]:
A=Float64[16 4 8;4 5 -4;8 -4 22];

In [14]:
b=Float64[4, 2, 5];

In [15]:
c = A\b


Out[15]:
3-element Array{Float64,1}:
 -0.25
  1.0 
  0.5 

In [16]:
?chol


search: chol cholfact cholfact! searchsortedlast chop chomp chmod Cshort

Out[16]:
chol(A, [LU]) -> F

Compute the Cholesky factorization of a symmetric positive definite matrix A and return the matrix F. If LU is Val{:U} (Upper), F is of type UpperTriangular and A = F'*F. If LU is Val{:L} (Lower), F is of type LowerTriangular and A = F*F'. LU defaults to Val{:U}.


In [21]:
chol(A, Val{:L})


Out[21]:
3x3 LowerTriangular{Float64,Array{Float64,2}}:
 4.0   0.0  0.0
 1.0   2.0  0.0
 2.0  -3.0  3.0

In [22]:
chol(A, Val{:U})


Out[22]:
3x3 UpperTriangular{Float64,Array{Float64,2}}:
 4.0  1.0   2.0
 0.0  2.0  -3.0
 0.0  0.0   3.0

In [18]:
round(A * c, 14) == b


Out[18]:
true