\Header{ginv}{Generalized Inverse of a Matrix}
\keyword{algebra}{ginv}
\begin{Description}\relax
Calculates the Moore-Penrose generalized inverse of a matrix
\code{X}.
\end{Description}
\begin{Usage}
\begin{verbatim}
ginv(X, tol = sqrt(.Machine$double.eps))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{X}] Matrix for which the Moore-Penrose inverse is required.

\item[\code{tol}] A relative tolerance to detect zero singular values.

\end{ldescription}
\end{Arguments}
\begin{Value}
A MP generalized inverse matrix for \code{X}.
\end{Value}
\begin{References}\relax
Venables, W. N. and Ripley, B. D. (1999)
\emph{Modern Applied Statistics with S-PLUS.} Third
Edition. Springer. p.100.
\end{References}
\begin{SeeAlso}\relax
\code{\Link{solve}}, \code{\Link{svd}}, \code{\Link{eigen}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Not run: 
# The function is currently defined as
function(X, tol = sqrt(.Machine$double.eps))
{
## Generalized Inverse of a Matrix
  dnx <- dimnames(X)
  if(is.null(dnx)) dnx <- vector("list", 2)
  s <- svd(X)
  nz <- s$d > tol * s$d[1]
  structure(
    if(any(nz)) s$v[, nz] %*% (t(s$u[, nz])/s$d[nz]) else X,
    dimnames = dnx[2:1])
}
## End(Not run)\end{ExampleCode}
\end{Examples}

