python - 如何在分母中用平方根创建 sympy 分数?
问题描述
# 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))
错误。
推荐阅读
- awk - 如何重新排列文件每一行的文本?
- python - 通过python使用sendgrid时出现错误的请求错误
- xamarin.forms - Xamarin Form iOS - 分发应用程序长路径问题
- css - 如何使用 CSS 为特定的 Rel 链接设置样式
- java - Hazelcast 通过带有谓词的 MessageListener 过滤主题消息
- html - 插值内的 Angular 5 条件
- java - 有没有办法在 kotlin 中没有 Platform.runLater() 的情况下从另一个线程更新 FX-Properties?
- linux - 在ansible中找到最后一分钟内修改的最新文件?
- javascript - 如何在字符串中找到确切的单词?
- mysql - 需要有关 MySQL 分区的建议