I'm using the MathNet.Symbolics
library to simplyfy expressions like this :
string f = Infix.Print(Infix.ParseOrThrow("A+5*2"))
This works as expected (f = A+10
) but trying to get the root of a number is a lot harder than I expected. For example :
string f = Infix.Print(Infix.ParseOrThrow("sqrt(9)"))
f = "sqrt(9)
" instead of f = "3"
as you would expect.
string f = Infix.Print(Infix.ParseOrThrow("sqrt(x^2)"))
f = "sqrt(x^2)"
insted of f = "x"
string f = Infix.Print(Infix.ParseOrThrow("9^(1/2)"))
also doesn't work. Insted it gets simplified to f = "sqrt(9)"
How do I force it to calculate the sqrt of a number/variable?
Are there any other problems I could expect to run into when using the "auto-simplification" of MathNet.Symbolics
?
You need to run the expression through the
Evaluate
method: