Solve system of symbolic equations or solve a polynomial equation. Depending on types of arguments, it supports different modes. See Details and Examples.

solve(a, b, ...)

# S4 method for DenseMatrix
solve(a, b, ...)

# S4 method for VecBasic
solve(a, b, ...)

# S4 method for Basic
solve(a, b, ...)

Arguments

a, b

Objects, see details.

...

Not used.

Value

A VecBasic or DenseMatrix S4 object.

Details

solve is a generic function dispatched on the class of the first argument.

  • If a is a (square) DenseMatrix, it solves the equation a %*% x = b for x. (similar to solve.default())

  • If a is a DenseMatrix and b is missing, b is taken to be an identity matrix and solve will return the inverse of a. (similar to solve.default())

  • If a is a VecBasic, it solves the system of linear equations represented by a with regards to symbols represented in b.

  • If a is a Basic, it solves the polynomial equation represented by a with regards to the symbol represented in b.

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 )