This generic function solves the equation $a x = b$ for $x$.

# S3 method for yac_symbol
solve(a, b, ...)

Arguments

a

A yac_symbol

b

A yac_symbol or a value, see details and examples.

...

See details and examples.

Details

When a is a matrix and b not provided, this finds the inverse of a. When a is a matrix and a vector b is provided, the linear system of equations is solved.

Note that solving non-linear equations:

  • solve(a, b): find roots of a for variable b, i.e. yacas Solve(a == 0, b)

  • solve(a, b, v): find solutions to a == b for variable v, i.e. yacas Solve(a == b, v)

This also works for a system of equations (when a is a vector)

Examples

A <- outer(0:3, 1:4, "-") + diag(2:5)
a <- 1:4
B <- ysym(A)
b <- ysym(a)
solve(A)
#>             [,1]        [,2]        [,3]        [,4]
#> [1,]  0.18316832  0.02970297  0.20297030  0.30693069
#> [2,] -0.16831683  0.29702970  0.02970297  0.06930693
#> [3,] -0.09405941 -0.06930693  0.19306931 -0.04950495
#> [4,] -0.04950495 -0.08910891 -0.10891089  0.07920792
solve(B)
#> {{   37/202,     3/101,    41/202,    31/101},
#>  {(-17)/101,    30/101,     3/101,     7/101},
#>  {(-19)/202,  (-7)/101,    39/202,  (-5)/101},
#>  { (-5)/101,  (-9)/101, (-11)/101,     8/101}} 
solve(A, a)
#> [1]  2.0792079  0.7920792  0.1485149 -0.2376238
solve(B, b)
#> {210/101, 80/101, 15/101, (-24)/101} 

poly <- ysym("x^2 - x - 6")
solve(poly, "x")    # Solve(poly == 0, x)
#> {x==(-2), x==3} 
solve(poly, 3, "x") # Solve(poly == 3, x)
#> {x==(Sqrt(37)+1)/2, x==(1-Sqrt(37))/2}