Inverse of a symmetric positive-definite matrix
pd.solve.RdThe inverse of a symmetric positive-definite matrix and its log-determinant
Arguments
- x
a symmetric positive-definite matrix.
- silent
a logical value which indicates the action to take in case of an error. If
silent==TRUEand an error occurs, the function silently returns aNULLvalue; ifsilent==FALSE(default), an error generates astopwith an error message.- log.det
a logical value to indicate whether the log-determinant of
xis required (default isFALSE).
Value
the inverse matrix of x; if log.det=TRUE, this inverse has an
attribute which contains the logarithm of the determinant of x.
Details
The function checks that x is a symmetric positive-definite
matrix. If an error is detected, an action is taken which depends on the
value of the argument silent.
Examples
x <- toeplitz(rev(1:4))
x.inv <- pd.solve(x)
print(x.inv %*% x)
#> [,1] [,2] [,3] [,4]
#> [1,] 1.000000e+00 2.220446e-16 -8.326673e-17 5.551115e-17
#> [2,] 3.682912e-16 1.000000e+00 2.166951e-16 2.987480e-17
#> [3,] 1.110223e-16 4.440892e-16 1.000000e+00 0.000000e+00
#> [4,] -1.110223e-16 -2.220446e-16 -2.220446e-16 1.000000e+00
x.inv <- pd.solve(x, log.det=TRUE)
logDet <- attr(x.inv, "log.det")
print(abs(logDet - determinant(x, logarithm=TRUE)$modulus))
#> [1] 0
#> attr(,"logarithm")
#> [1] TRUE