23 lines
665 B
Text
23 lines
665 B
Text
function cholesky(sequence matrix)
|
|
integer l = length(matrix)
|
|
sequence chol = repeat(repeat(0,l),l)
|
|
for row=1 to l do
|
|
for col=1 to row do
|
|
atom x = matrix[row][col]
|
|
for i=1 to col do
|
|
x -= chol[row][i] * chol[col][i]
|
|
end for
|
|
chol[row][col] = iff(row == col ? sqrt(x) : x/chol[col][col])
|
|
end for
|
|
end for
|
|
return chol
|
|
end function
|
|
|
|
ppOpt({pp_Nest,1})
|
|
pp(cholesky({{ 25, 15, -5 },
|
|
{ 15, 18, 0 },
|
|
{ -5, 0, 11 }}))
|
|
pp(cholesky({{ 18, 22, 54, 42},
|
|
{ 22, 70, 86, 62},
|
|
{ 54, 86, 174, 134},
|
|
{ 42, 62, 134, 106}}))
|