Hitung faktorisasi Choleski dari matriks persegi pasti positif simetris nyata.
chol(x, …)<p></p><p># S3 method for default
chol(x, pivot = FALSE, LINPACK = FALSE, tol = -1, …)</p>
| Parameter | Deskripsi |
|---|---|
x |
an object for which a method exists. The default method applies to numeric (or logical) symmetric, positive-definite matrices. |
… |
arguments to be based to or from methods. |
pivot |
Should pivoting be used? |
LINPACK |
logical. Should LINPACK be used (now ignored)? |
tol |
A numeric tolerance for use with pivot = TRUE. |
# NOT RUN {
( m <- matrix(c(5,1,1,3),2,2) )
( cm <- chol(m) )
t(cm) %*% cm #-- = 'm'
crossprod(cm) #-- = 'm'
# now for something positive semi-definite
x <- matrix(c(1:5, (1:5)^2), 5, 2)
x <- cbind(x, x[, 1] + 3*x[, 2])
colnames(x) <- letters[20:22]
m <- crossprod(x)
qr(m)$rank # is 2, as it should be
# chol() may fail, depending on numerical rounding:
# chol() unlike qr() does not use a tolerance.
try(chol(m))
(Q <- chol(m, pivot = TRUE))
## we can use this by
pivot <- attr(Q, "pivot")
crossprod(Q[, order(pivot)]) # recover m
## now for a non-positive-definite matrix
( m <- matrix(c(5,-5,-5,3), 2, 2) )
try(chol(m)) # fails
(Q <- chol(m, pivot = TRUE)) # warning
crossprod(Q) # not equal to m
# }