R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > # chlsoi.r J F Monahan, June 2008 > # > # Cholesky factorization and inverse of a positive definite matrix > A <- matrix(c(4,2,2,4, 2,5,7,0, 2,7,19,11, 4,0,11,25), 4, 4) > "matrix" [1] "matrix" > A [,1] [,2] [,3] [,4] [1,] 4 2 2 4 [2,] 2 5 7 0 [3,] 2 7 19 11 [4,] 4 0 11 25 > Lt <- chol(A) > "Cholesky factor -- transposed to be upper triangular" [1] "Cholesky factor -- transposed to be upper triangular" > Lt [,1] [,2] [,3] [,4] [1,] 2 1 1 2 [2,] 0 2 3 -1 [3,] 0 0 3 4 [4,] 0 0 0 2 > AI <- chol2inv(Lt) > "inverse" [1] "inverse" > AI [,1] [,2] [,3] [,4] [1,] 0.9461806 -1.15625 0.5555556 -0.3958333 [2,] -1.1562500 2.06250 -1.0000000 0.6250000 [3,] 0.5555556 -1.00000 0.5555556 -0.3333333 [4,] -0.3958333 0.62500 -0.3333333 0.2500000 > "multiply to get identity" [1] "multiply to get identity" > A %*% AI [,1] [,2] [,3] [,4] [1,] 1.000000e+00 0 -4.440892e-16 1.110223e-16 [2,] -9.992007e-16 1 -9.992007e-16 2.775558e-16 [3,] -2.164935e-15 0 1.000000e+00 4.440892e-16 [4,] -7.216450e-16 0 -7.216450e-16 1.000000e+00 > "solve equations" [1] "solve equations" > b <-c( -1, 1, 2.5, .25) > "Right hand side" [1] "Right hand side" > b [1] -1.00 1.00 2.50 0.25 > x <- AI %*% b > "Solution" [1] "Solution" > x [,1] [1,] -0.8125 [2,] 0.8750 [3,] -0.2500 [4,] 0.2500 > rm(list=ls()) > q()