Solve system of symbolic equations or solve a polynomial equation. Depending on types of arguments, it supports different modes. See Details and Examples.
Usage
solve(a, b, ...)
# S4 method for class 'DenseMatrix'
solve(a, b, ...)
# S4 method for class 'VecBasic'
solve(a, b, ...)
# S4 method for class 'Basic'
solve(a, b, ...)Details
solve is a generic function dispatched on the class of the first argument.
If
ais a (square) DenseMatrix, it solves the equationa %*% x = bforx. (similar tosolve.default())If
ais a DenseMatrix andbis missing,bis taken to be an identity matrix andsolvewill return the inverse ofa. (similar tosolve.default())If
ais a VecBasic, it solves the system of linear equations represented byawith regards to symbols represented inb.If
ais a Basic, it solves the polynomial equation represented by a with regards to the symbol represented inb.
Examples
## Inverse of a symbolic matrix
mat <- Matrix(c("A", "B", "C", "D"), 2)
solve(mat)
#> DenseMatrix of dim 2 x 2
#> [(1 + B*C/(A*(D - B*C/A)))/A, -C/(A*(D - B*C/A))]
#> [-B/(A*(D - B*C/A)), (D - B*C/A)**(-1)]
## Solve a %*% x == b
a <- Matrix(c("a11", "a21", "a12", "a22"), 2) # a is a 2x2 matrix
b <- Vector("b1", "b2") # b is a length 2 vector
solve(a, b) # Solution of x (2x1 matrix)
#> DenseMatrix of dim 2 x 1
#> [(b1 - a12*(b2 - b1*a21/a11)/(a22 - a21*a12/a11))/a11]
#> [(b2 - b1*a21/a11)/(a22 - a21*a12/a11)]
## Solve the system of linear equations represented by a with regards to
## symbols in b
a <- Vector(~ -2*x + y - 4, # A system of linear equations
~ 3*x + y - 9)
b <- Vector(~x, ~y) # Symbols to solve (x and y)
solve(a, b) # Solution of x and y
#> VecBasic of length 2
#> V( 1, 6 )