logo

Methods for Symbolic Computation in Julia 📂Julia

Methods for Symbolic Computation in Julia

Overview

Symbolic operations in Julia can be used through the SymEngine.jl1 package.

Code

Defining Symbols

Symbols can be defined in the following way.

julia> using SymEngine

julia> x = symbols(:x)
x

julia> x, y = symbols("x y")
(x, y)

julia> @vars x, y
(x, y)
julia> x = symbols(:x)
x

julia> f = 2x + x^2 + cos(x)
2*x + x^2 + cos(x)

Vectors and Matrices

julia> v = [symbols("v_▷eq1◁i$j") for i in 1:2, j in 1:3]
2×3 Matrix{Basic}:
 a_11  a_12  a_13
 a_21  a_22  a_23

julia> A*v
2-element Vector{Basic}:
 v_1*a_11 + v_2*a_12 + v_3*a_13
 v_1*a_21 + v_2*a_22 + v_3*a_23

julia> @vars a, b, c, d, x, y
(a, b, c, d, x, y)

julia> [a b; c d] * [a x; b y]
2×2 Matrix{Basic}:
 a^2 + b^2  a*x + b*y
 a*c + b*d  c*x + d*y

Differentiation

Symbolic differentiation can also be used with the Calculus.jl package.

julia> f = 2x + x^2 + cos(x)
2*x + x^2 + cos(x)

julia> diff(f, x)
2 + 2*x - sin(x)

Environment

  • OS: Windows10
  • Version: Julia v1.7.1, SymEngine v0.8.7