The R Project SVN R

Rev

Rev 85065 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/base/man/backsolve.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
88574 hornik 3
% Copyright 1995-2025 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
2 r 6
\name{backsolve}
56186 murdoch 7
\alias{backsolve}
7782 hornik 8
\alias{forwardsolve}
3076 pd 9
\title{Solve an Upper or Lower Triangular System}
7782 hornik 10
\description{
60330 ripley 11
  Solves a triangular system of linear equations.
7782 hornik 12
}
2 r 13
\usage{
62172 hornik 14
   backsolve(r, x, k = ncol(r), upper.tri = TRUE,
15
             transpose = FALSE)
16
forwardsolve(l, x, k = ncol(l), upper.tri = FALSE,
17
             transpose = FALSE)
2 r 18
}
19
\arguments{
60330 ripley 20
  \item{r, l}{an upper (or lower) triangular matrix giving the
7324 ripley 21
    coefficients for the system to be solved.  Values below (above)
22
    the diagonal are ignored.}
42961 ripley 23
  \item{x}{a matrix whose columns give the right-hand sides for
7324 ripley 24
    the equations.}
85065 smeyer 25
  \item{k}{the number of columns of \code{r} and rows of \code{x} to use.}
7324 ripley 26
  \item{upper.tri}{logical; if \code{TRUE} (default), the \emph{upper}
3076 pd 27
    \emph{tri}angular part of \code{r} is used.  Otherwise, the lower one.}
7324 ripley 28
  \item{transpose}{logical; if \code{TRUE}, solve \eqn{r' * y = x} for
10443 hornik 29
    \eqn{y}, i.e., \code{t(r) \%*\% y == x}.}
2 r 30
}
60330 ripley 31
\details{
32
   Solves a system of linear equations where the coefficient matrix is
33
   upper (or \sQuote{right}, \sQuote{R}) or lower (\sQuote{left},
34
   \sQuote{L}) triangular.
35
 
36
  \code{x <- backsolve   (R, b)} solves \eqn{R x = b}, and\cr
37
  \code{x <- forwardsolve(L, b)} solves \eqn{L x = b}, respectively.
60335 ripley 38
 
39
  The \code{r}/\code{l} must have at least \code{k} rows and columns,
40
  and \code{x} must have at least \code{k} rows.
61433 ripley 41
 
60330 ripley 42
  This is a wrapper for the level-3 BLAS routine \code{dtrsm}.
43
}
2 r 44
\value{
7782 hornik 45
  The solution of the triangular system.  The result will be a vector if
46
  \code{x} is a vector and a matrix if \code{x} is a matrix.
2 r 47
}
48
\references{
88574 hornik 49
  \bibshow{R:Becker+Chambers+Wilks:1988,
50
    R:Dongarra+Bunch+Moler:1979}
2 r 51
}
52
\seealso{
7782 hornik 53
  \code{\link{chol}},
54
  \code{\link{qr}},
55
  \code{\link{solve}}.
2 r 56
}
57
\examples{
25118 hornik 58
## upper triangular matrix 'r':
1566 maechler 59
r <- rbind(c(1,2,3),
60
           c(0,1,1),
61
           c(0,0,2))
62
( y <- backsolve(r, x <- c(8,4,2)) ) # -1 3 1
63
r \%*\% y # == x = (8,4,2)
23025 ripley 64
backsolve(r, x, transpose = TRUE) # 8 -12 -5
2 r 65
}
286 maechler 66
\keyword{algebra}
67
\keyword{array}