Total and Partial Matrix Inversion using Gauss-Jordan Sweep Operator
This function inverts or partially inverts a matrix using pivoting (the sweep operator). It is useful for sequential model-building.
matinv(a, which, negate=TRUE, eps=1e-12)
- square matrix to invert or partially invert. May have been inverted or partially inverted previously by matinv, in which case its "swept" attribute is updated. Will un-invert if already inverted.
- vector of column/row numbers in a to invert. Default is all, for total inverse.
- So that the algorithm can keep track of which pivots have been swept as well as roundoff errors, it actually returns the negative of the inverse or partial inverse. By default, these elements are negated to give the usual expected result. Set negate=FAL
- singularity criterion
- a square matrix, with attributes "rank" and "swept".
Clarke MRB (1982). Algorithm AS 178: The Gauss-Jordan sweep operator with detection of collinearity. Appl Statist 31:166--9.
Ridout MS, Cobb JM (1986). Algorithm AS R78 : A remark on algorithm AS 178: The Gauss-Jordan sweep operator with detection of collinearity. Appl Statist 38:420--2.
a <- diag(1:3) a.inv1 <- matinv(a, 1, negate=FALSE) #Invert with respect to a[1,1] a.inv1 a.inv <- -matinv(a.inv1, 2:3, negate=FALSE) #Finish the job a.inv solve(a)