# From jupyter notebook
import sympy
sympy.init_printing()
x1 = sympy.Rational(1, 2)
x2 = sympy.sqrt(2)
# ERROR: can't do this..
x3 = sympy.Rational(1, sympy.sqrt(2))
# ERROR: can't do this either
x4 = sympy.Rational(1, x2)
如何象征性地将 sqrt 放在方程的分母中而不使用浮点数?
当你需要 1 / sqrt(2),这样做:
x1 = 1 / sympy.sqrt(2)
当你需要 1 / 2,这样做:
x1 = sympy.Rational(1,2)
不要这样做:
x1 = sympy.Rational(1, sympy.sqrt(2))
错误。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(42条)