a %*% x = b
for x
,
where b
can be either a vector or a matrix.
solve(a, b, ...)
"solve"(a, b, tol, LINPACK = FALSE, ...)
b
is taken to be
an identity matrix and solve
will return the inverse of a
.a
. The default is .Machine$double.eps
. Not
currently used with complex matrices a
.DGESV
and ZGESV
. LAPACK is from http://www.netlib.org/lapack.a
or b
can be complex, but this uses double complex
arithmetic which might not be available on all platforms. The row and column names of the result are taken from the column names
of a
and of b
respectively. If b
is missing the
column names of the result are the row names of a
. No check is
made that the column names of a
and the row names of b
are equal.
For back-compatibility a
can be a (real) QR decomposition,
although qr.solve
should be called in that case.
qr.solve
can handle non-square systems.
Unsuccessful results from the underlying LAPACK code will result in an error giving a positive error code: these can only be interpreted by detailed study of the FORTRAN code.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
solve.qr
for the qr
method,
chol2inv
for inverting from the Choleski factor
backsolve
, qr.solve
.
hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }
h8 <- hilbert(8); h8
sh8 <- solve(h8)
round(sh8 %*% h8, 3)
A <- hilbert(4)
A[] <- as.complex(A)
## might not be supported on all platforms
try(solve(A))
Run the code above in your browser using DataLab