\Header{solve}{Solve a System of Equations}
\methalias{solve.default}{solve}
\methalias{solve.qr}{solve}
\keyword{algebra}{solve}
\begin{Description}\relax
This generic function solves the equation \code{a \%*\% x = b} for \code{x},
where \code{b} can be either a vector or a matrix.\end{Description}
\begin{Usage}
\begin{verbatim}
solve(a, b, tol = 1e-7)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{a}] a numeric matrix containing the coefficients of the linear
system.
\item[\code{b}] a numeric vector or matrix giving the right-hand side(s) of
the linear system.  If omitted, \code{b} is taken to be an identity
matrix and \code{solve} will return the inverse of \code{a}.
\item[\code{tol}] the tolerance for detecting linear dependencies in the
columns of \code{a}.
\end{ldescription}
\end{Arguments}
\begin{SeeAlso}\relax
\code{\Link{backsolve}}, \code{\Link{qr.solve}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }
h8 <- hilbert(8); h8
solve(h8) # gives error: `singular'
sh8 <- solve(h8, tol = 1e-10)
round(sh8 %*% h8, 3)
\end{ExampleCode}
\end{Examples}

