diagv function

Matrix product with a diagonal matrix

Matrix product with a diagonal matrix

Computes faster the product of a diagonal matrix times a full matrix.

diagv(v, M)

Arguments

  • v: A numeric vector specifying the elements on the diagonal of a matrix.
  • M: A numeric matrix compatible with the product DvMD_v M.

Details

Computes N=DvMN = D_v M where DvD_v is diagonal avoiding the diag operator.

Returns

A matrix N.

See Also

diag

Examples

v <- 1:1000 M <- matrix(runif(3000), 1000, 3) dim(diagv(v, M))