Reputation: 566
I have a linear equation in string format for example something like this:
equation = "2 * x + 1 = 17"
what would be the best approach to solving the equation for x
?
Upvotes: 1
Views: 173
Reputation: 18217
As another option, using Symbolics.jl
:
julia> using Symbolics
julia> equation = "2 * x + 1 = 17"
"2 * x + 1 = 17"
julia> @variables x
1-element Vector{Num}:
x
julia> eqn = eval(Meta.parse(replace(equation, "=" => "~")))
1 + 2x ~ 17
julia> Symbolics.solve_for(eqn, x)
8.0
(not sure which equations Symbolics knows how to solve)
Upvotes: 1