quadform: Quadratic form of a matrix and a vector

Description Usage Arguments Details Value

View source: R/helper.r

Description

We compute the quadratic form of a vector and a matrix in an efficient manner. Let x be a real vector of length p, and let A be a p x p real matrix. Then, we compute the quadratic form q = x' A x.

Usage

1
quadform(A, x)

Arguments

A

matrix of dimension p x p

x

vector of length p

Details

A naive way to compute the quadratic form is to explicitly write t(x) \%*\% A \%*\% x, but for large p, this operation is inefficient. We provide a more efficient method below.

Note that we have adapted the code from: https://stat.ethz.ch/pipermail/r-help/2005-November/081940.html

Value

scalar value


sparsediscrim documentation built on July 1, 2021, 9:07 a.m.