[英]Sympy simplification is broken (square roots)?
I tried this in python shell我在 python shell 中试过这个
>>> from sympy import sqrt
>>> sqrt((-9/10 + 6*sqrt(3)/5)**2 + (6/5 + 9*sqrt(3)/10)**2)
sqrt((-0.9 + 6*sqrt(3)/5)**2 + (1.2 + 9*sqrt(3)/10)**2)
and when type it in google:当在谷歌中输入时:
So how do I get numpy to give me a more simpilified result (it won't always be an int so I cant use evalf or N)那么如何让 numpy 给我一个更简化的结果(它并不总是一个 int 所以我不能使用 evalf 或 N)
There are 2 things missing here:这里缺少两件事:
simplify
the expression if it's something complex.simplify
表达式。Rational
whenever possible, to avoid numerical inaccuraties of floating point arithmeticRational
,以避免浮点运算的数值不准确All in all:总而言之:
>>> from sympy import Rational, simplify, sqrt
>>> simplify(sqrt((-Rational(9, 10) + Rational(6,5)*sqrt(3))**2 + (Rational(6,5) + Rational(9,10)*sqrt(3))**2))
3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.