Computes t(v) %*% solve(X) %*% v (for a vector
v) or t(V) %*% solve(X) %*% V (for a matrix
V) efficiently via the Cholesky factor of X, without
forming the inverse.
Arguments
- factor
An
amCholobject fromchol_factor.- v
Numeric vector or matrix. For a vector, the result is a scalar; for a matrix with
pcolumns, the result is ap x pmatrix.
Value
Scalar double (when v is a vector) or numeric matrix
of dimensions ncol(v) x ncol(v) containing the quadratic
form.
Examples
m <- crossprod(matrix(rnorm(16), 4, 4)) + diag(4)
A <- adgeMatrix(m)
fac <- chol_factor(A)
v <- rnorm(4)
quad_form(fac, v)
#> [1] 1.776342