Solve Linear Equations and Invert Matrices - Generic Function

DESCRIPTION:

Performs matrix inversion if given a single argument, or solves systems of linear equations if given two arguments.

This function is an S Version 3 generic (see Methods); method functions can be written to handle specific S Version 3 classes of data. Classes which already have methods for this function include:
svd.right , upper.

USAGE:

solve(a, b, ...) 
solve.default(a, b) 

REQUIRED ARGUMENTS:

a
a representation of a square non-singular matrix. In particular a QR decomposition as output by the qr function is suitable.

OPTIONAL ARGUMENTS:

b
vector or matrix of coefficients.

VALUE:

the solution x to the system of equations a %*% x = b, if b is present. Otherwise, the inverse of a.

DETAILS:

If given a non-singular matrix a, will give the inversion of the matrix. If given two arguments, a and b, will give the solution x for the system of equations.

SEE ALSO:

, , , , .

for the transpose of a matrix.

for a generalized matrix inverse (matrix may be singular).

to solve a system of nonlinear equations (using function solveNonlinear in Examples section).

EXAMPLES:

amat <- matrix(c(19,8,11,2,18,17,15,19,10), nrow = 3) 
ainv <- solve(amat)    # invert amat 
aqr <- qr(amat) 
b1 <- c(9,5,14) 
solve(aqr, b1)