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
- If given two arguments, a and b, the function returns
the solution x for the system of equations a %*% x == b.
- If given only a non-singular matrix a, the function returns its inverse.
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 TIBCO Enterprise Runtime for R and Open-source R
- The LINPACK argument, which is available in open-source R, is ignored in TIBCO Enterprise Runtime for R.
- If b contains missing values (NAs), open-source R solve(qr(a), b) returns a vector of zeros; in TIBCO Enterprise Runtime for R an error is returned.
See Also
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