Substitute symbol for value
subs(sym, nms, vls)
Expression
Names of symbols (see Details)
Values that nms
is substituted with (see Details)
Two different ways to call this function is supported:
Supplying nms
as a named list and omitting vls
.
If two components have the same name, the behaviour is undefined.
Supplying both nms
and vls
See 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₂₂ ⎦