sympy - 奇怪的行为变成了 integer.Numbers 在解决方案中找到了很多数字

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?