如何解决sympy - 奇怪的行为变成了 integer.Numbers 在解决方案中找到了很多数字
感谢您有机会提出宝贵意见 我是 sympy 工具包的新手,我尝试执行一些硬积分来测试该工具。 在其中之一中,它在解决方案中返回奇怪的长数字。 下面的积分计算:
integrate((atan(1/(1-x^2)),x)
。
我没有添加解决方案,因为它太大而无法链接到我的帖子中。 所以我试图知道为什么以及我们是否可以操纵开始表达式以获得最佳的符号最终解决方案。 我希望我的例子对发现奇怪的行为有用。 祝你2021年更美好。 再见 A.
解决方法
我认为这是“启发式”算法的输出,它有时会生成看起来很复杂的解决方案。该算法采用相对间接的方法来寻找初等反导数。
我得到的完整输出是:
In [156]: i = integrate(atan(1/(1-x**2)),x)
In [157]: i
Out[157]:
________ ________ ⎛ 1 ⎞ ________ ________ ⎛ 1 ⎞
3156404596⋅x⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 ⋅atan⎜──────⎟ 2231915094⋅√2⋅x⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 ⋅atan⎜──────⎟
⎜ 2⎟ ⎜ 2⎟
⎝1 - x ⎠ ⎝1 - x ⎠
- ──────────────────────────────────────────────────────────────────────── + ────────────────────────────────────────────────────────────────
________ ________ ________ ________ ________ ________ ________
- 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱
4 ___ ________ ⎛ 2 4 ___ ________ ⎞ 3/4 ________ ⎛ 2 4 ___ ___
1115957547⋅╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x - 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2 + 4⋅√2⎠ 789101149⋅2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x - 4⋅╲╱ 2 ⋅x⋅╲╱ √2
──────── - ──────────────────────────────────────────────────────────────────────── + ───────────────────────────────────────────────────────
________ ________ ________ ________ ________ ________ ________ __
√2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 2231915094⋅√2⋅╲╱ 2
_____ ⎞ 3/4 ________ ⎛ 2 4 ___ ________ ⎞ 4 ___ ________ ⎛ 2 4 _
+ 2 + 4⋅√2⎠ 789101149⋅2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x + 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2 + 4⋅√2⎠ 1115957547⋅╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x + 4⋅╲╱
───────────────── - ──────────────────────────────────────────────────────────────────────── + ──────────────────────────────────────────────
______ ________ ________ ________ ________ ________ ________ ________
- √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 223191509
4 ___ ________ ⎛ 1 ⎞ 3/4 ___
924489502⋅╲╱ 2 ⋅╲╱ 2 - √2 ⋅atan⎜──────⎟ 653712796⋅2 ⋅╲╱ 2
__ ________ ⎞ ⎜ 2⎟
2 ⋅x⋅╲╱ √2 + 2 + 4⋅√2⎠ ⎝1 - x ⎠
────────────────────────── - ──────────────────────────────────────────────────────────────────────── + ─────────────────────────────────────
________ ________ ________ ________ ________ ________ ________ ________
4⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 +
⎛ 3/4 ________⎞
_____ ⎛ 1 ⎞ 4 ___ ________ ⎜ 2 ⋅x ╲╱ √2 + 2 ⎟ 3/4 __
- √2 ⋅atan⎜──────⎟ 4463830188⋅╲╱ 2 ⋅╲╱ √2 + 2 ⋅atan⎜────────── - ──────────⎟ 3156404596⋅2 ⋅╲╱ √
⎜ 2⎟ ⎜ ________ ________⎟
⎝1 - x ⎠ ⎝╲╱ 2 - √2 ╲╱ 2 - √2 ⎠
─────────────────────────────────── - ──────────────────────────────────────────────────────────────────────── + ────────────────────────────
________ ________ ________ ________ ________ ________ ________ __
2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √
⎛ 3/4 ________⎞
______ ⎜ 2 ⋅x ╲╱ √2 + 2 ⎟
2 + 2 ⋅atan⎜────────── - ──────────⎟
⎜ ________ ________⎟
⎝╲╱ 2 - √2 ╲╱ 2 - √2 ⎠
────────────────────────────────────────────
______ ________ ________
2 + 2 + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2
我们可以简化它:
In [158]: i2 = powsimp(radsimp(i),deep=True)
In [159]: i2
Out[159]:
3/4
2
4 ___ ________ ⎛ 2 4 ___ ________ ⎞ 4 ___ ________ ⎛ 2 4 ___ ________ ⎞
⎛ 1 ⎞ ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x - 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2 + 4⋅√2⎠ ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x + 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2 + 4⋅√2⎠
- x⋅atan⎜──────⎟ - ──────────────────────────────────────────────────────── + ──────────────────────────────────────────────────────── - ────
⎜ 2 ⎟ 4 4
⎝x - 1⎠
________ ⎛ 1 ⎞ 4 ___ ________ ⎛ 1 ⎞
⋅╲╱ 2 - √2 ⋅atan⎜──────⎟ ╲╱ 2 ⋅╲╱ 2 - √2 ⋅atan⎜──────⎟
⎜ 2 ⎟ ⎜ 2 ⎟
⎝x - 1⎠ ⎝x - 1⎠ 4 ___ ________ ⎛ 3/4 ________ 4 ___ ________ ⎞
──────────────────────── - ───────────────────────────── + ╲╱ 2 ⋅╲╱ √2 + 2 ⋅atan⎝- 2 ⋅x⋅╲╱ 2 - √2 - ╲╱ 2 ⋅x⋅╲╱ 2 - √2 + 1 + √2⎠
2 2
In [160]: i2.collect(i2.atoms(log,atan))
Out[160]:
⎛ 3/4 ________ 4 ___ ________⎞ 4 ___ ________ ⎛ 2 4 ___ ________ ⎞ 4 ___ ________ ⎛ 2
⎜ 2 ⋅╲╱ 2 - √2 ╲╱ 2 ⋅╲╱ 2 - √2 ⎟ ⎛ 1 ⎞ ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x - 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2 + 4⋅√2⎠ ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x
⎜-x - ─────────────── - ────────────────⎟⋅atan⎜──────⎟ - ──────────────────────────────────────────────────────── + ─────────────────────────
⎝ 2 2 ⎠ ⎜ 2 ⎟ 4
⎝x - 1⎠
4 ___ ________ ⎞
+ 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2 + 4⋅√2⎠ 4 ___ ________ ⎛ 3/4 ________ 4 ___ ________ ⎞
─────────────────────────────── + ╲╱ 2 ⋅╲╱ √2 + 2 ⋅atan⎝- 2 ⋅x⋅╲╱ 2 - √2 - ╲╱ 2 ⋅x⋅╲╱ 2 - √2 + 1 + √2⎠
4
我们可以通过微分来检查结果(尽管再次需要一些简化):
In [190]: cancel(cancel(i2.diff(x),extension=True))
Out[190]:
⎛ 1 ⎞
-atan⎜──────⎟
⎜ 2 ⎟
⎝x - 1⎠
这与原始被积函数相同,只是去掉了减号 (atan(-y) = -atan(y)
)。
Wolfram Alpha 有一个更简单的结果,尽管它在积分为实数的情况下也使用复数: https://www.wolframalpha.com/input/?i=integrate%28atan%281%2F%281-x**2%29%29%2C+x%29
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。