I am trying to do some work around an object of type CholeskyDecomposition in F#. However, I cannot figure out how to access the elements of a CholeskyDecomposition class. I've tried referring to it as <object of type CholeskyDecomposition>.[row, col]
but that does not work.
Can anybody help?
Sep 3, 2012 at 6:31 PM
Every matrix decomposition is represented by a decomposition object (CholeskyDecomposition, QRDecomposition, SingularValueDecomposition) that is a container for the various factor matrices. To get to an individual factor matrix, call the method
specific to it on the decomposition object. Then you can access the individual elements of elements of that matrix, or use the matrix in other operations. In the case of the CholeskyDecomposition class, the factor matrix is obtained from SquareRootMatrix().
Here is some example code:
// Simple routine to print a matrix
let PrintMatrix (M : AnyRectangularMatrix) =
for r = 0 to M.RowCount-1 do
for c = 0 to M.ColumnCount-1 do
printf "%A " M.[r, c]
// Define a positve definite, symmetric matrix
let A = new SymmetricMatrix(2)
A.[0,0] <- 2.0
A.[1,1] <- 3.0
A.[0,1] <- 1.0
// Cholesky decompose it as A = B B^T
let CD = A.CholeskyDecomposition()
// Get the factor matrix B
let B = CD.SquareRootMatrix()
// Verify that the factorization works
PrintMatrix(B * B.Transpose())
Once you have B here, you can access B.[row, col].
Cool, that worked. :)