solve
Solve Linear Equations and Invert Matrices

Description

Solves a non-singular system of linear equations a %*% x == b or, if b is omitted, inverts the matrix a. The function solve is generic.

Usage

solve(a, b, ...) 
## S3 method for class 'solve':
default(a, b, tol = .Machine$double.eps, ...) 
## S3 method for class 'solve':
qr(a, b, ...) 

Arguments

a a non-singular square numeric or complex matrix, or a QR decomposition of such a matrix (as made by the qr function).
b a numeric or complex (if a is complex) vector, or a matrix giving the right hand side of the equation to be solved. a %*% x == b. NROW(b) must match NCOL(a); b can have any number of columns. Its default value is the identity matrix of order NCOL(a), meaning the result of solve is the inverse of a.
tol a small positive numeric value. If the estimated reciprocal condition number of a is less than tol, then the matrix is considered singular, and an error is given.
... additional arguments passed to other methods for solve but are ignored by these methods.

Details

The default method uses the LAPACK function dgesv or, for complex matrices, zgesv, to solve the system using the LU decomposition. See http://www.netlib.org/lapack/ for more details.
Value
returns the inverse of a or, if b is present, it returns the solution x to the system of equations a %*% x = b. It has the same dimensions as b.
Differences between Spotfire Enterprise Runtime for R and Open-source R
See Also
chol, qr, qr.coef, qr.solve, svd, t for the transpose of a matrix.
Examples
amat <- matrix(c(19,8,11,2,18,17,15,19,10), nrow = 3) 
b1 <- c(9,5,14) 
solve(amat, b1)      # solve with solve.default
aqr <- qr(amat) 
solve(aqr, b1)       # solve with solve.qr
solve(amat) %*% b1   # solve same eqn the slow and less accurate way
Package base version 6.1.1-7
Package Index