# Introduction to ‘caracas’

library(caracas)

## Quick start

x <- symbol('x')
eq <- 2*x^2 - x
eq
#> [caracas]:    2
#>            2⋅x  - x
as.character(eq)
#> [1] "2*x^2 - x"
as_r(eq)
#> expression(2 * x^2 - x)
tex(eq)
#> [1] "2 x^{2} - x"

$2 x^{2} - x$

solve_sys(eq, x)
#> Solution 1:
#>   x =  0
#> Solution 2:
#>   x =  1/2
der(eq, x)
#> [caracas]: 4⋅x - 1
subs(eq, x, "y")
#> [caracas]:    2
#>            2⋅y  - y

## Linear algebra

A <- matrix(c("x", 2, 0, "2*x"), 2, 2)
B <- as_symbol(A)
B
#> [caracas]: ⎡x   0 ⎤
#>            ⎢      ⎥
#>            ⎣2  2⋅x⎦
Binv <- inv(B) # or solve_lin(B)
Binv
#> [caracas]: ⎡ 1      ⎤
#>            ⎢ ─    0 ⎥
#>            ⎢ x      ⎥
#>            ⎢        ⎥
#>            ⎢-1    1 ⎥
#>            ⎢───  ───⎥
#>            ⎢  2  2⋅x⎥
#>            ⎣ x      ⎦
tex(Binv)
#> [1] "\\left[\\begin{matrix}\\frac{1}{x} & 0\\\\- \\frac{1}{x^{2}} & \\frac{1}{2 x}\\end{matrix}\\right]"

$\left[\begin{matrix}\frac{1}{x} & 0\\- \frac{1}{x^{2}} & \frac{1}{2 x}\end{matrix}\right]$

eigen_val(Binv)
#> [[1]]
#> [[1]]$eigval #> [caracas]: 1 #> ─ #> x #> #> [[1]]$eigmult
#> [1] 1
#>
#>
#> [[2]]
#> [[2]]$eigval #> [caracas]: 1 #> ─── #> 2⋅x #> #> [[2]]$eigmult
#> [1] 1

## More examples

Please find more examples in the other vignettes.