sherman.morrison: Sherman-Morrison formula

Description Usage Arguments Details Value Examples

View source: R/sherman_morrison.R

Description

The Sherman-Morrison formula gives a convenient expression for the inverse of the rank 1 update (\bold{A} + \bold{bd}^T) where \bold{A} is a n\times n matrix and \bold{b}, \bold{d} are n-dimensional vectors. Thus

(\bold{A} + \bold{bd}^T)^{-1} = \bold{A}^{-1} - \frac{\bold{A}^{-1}\bold{bd}^T \bold{A}^{-1}}{1 + \bold{d}^T\bold{A}^{-1}\bold{b}}.

Usage

1
sherman.morrison(a, b, d = b, inverted = FALSE)

Arguments

a

a numeric matrix.

b

a numeric vector.

d

a numeric vector.

inverted

logical. If TRUE, a is supposed to contain its inverse.

Details

Method of sherman.morrison calls BLAS level 2 subroutines DGEMV and DGER for computational efficiency.

Value

a square matrix of the same order as a.

Examples

1
2
3
4
5
n <- 10
ones <- rep(1, n)
a <- 0.5 * diag(n)
z <- sherman.morrison(a, ones, 0.5 * ones)
z

fastmatrix documentation built on Oct. 18, 2021, 5:08 p.m.