Substitute symbol for value

subs(sym, nms, vls)

Arguments

sym

Expression

nms

Names of symbols (see Details)

vls

Values that nms is substituted with (see Details)

Details

Two different ways to call this function is supported:

  1. Supplying nms as a named list and omitting vls. If two components have the same name, the behaviour is undefined.

  2. Supplying both nms and vls See Examples.

Examples

if (has_sympy()) {
   x <- symbol('x')
   e <- 2*x^2
   e
   subs(e, "x", "2")
   subs(e, x, 2)
   subs(e, list(x = 2))
   
   A <- matrix_sym(2, 2, "a")
   B <- matrix_sym(2, 2, "b")
   e <- A %*% A
   subs(e, A, B)
}
#> c: ⎡    2                               ⎤
#>    ⎢ b₁₁  + b₁₂⋅b₂₁    b₁₁⋅b₁₂ + b₁₂⋅b₂₂⎥
#>    ⎢                                    ⎥
#>    ⎢                                 2  ⎥
#>    ⎣b₁₁⋅b₂₁ + b₂₁⋅b₂₂   b₁₂⋅b₂₁ + b₂₂   ⎦