我正在使用 MathNet.Symbolics
库来简化如下表达式:
string f = Infix.Print(Infix.ParseOrThrow("A+5*2"))
这按预期工作(f = A+10
),但尝试获取数字的根比我预期的要困难得多。例如:
string f = Infix.Print(Infix.ParseOrThrow("sqrt(9)"))
f = "sqrt(9)
"而不是您所期望的 f = "3"
。
string f = Infix.Print(Infix.ParseOrThrow("sqrt(x^2)"))
f = "sqrt(x^2)"
替换为 f = "x"
string f = Infix.Print(Infix.ParseOrThrow("9^(1/2)"))
也不起作用。安装后,它被简化为 f = "sqrt(9)"
如何强制它计算数字/变量的 sqrt?
使用 MathNet.Symbolics
的“自动简化”功能时,我可能会遇到任何其他问题吗?
最佳答案
您需要通过Evaluate
方法运行表达式:
string f = Infix.Print(Infix.ParseOrThrow("sqrt(9)"));
double result = Evaluate.Evaluate(null, f);
关于mathnet-numerics - 如何计算 MathNet.Symbolics 中的 sqrt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46180952/