SymPy 无法求解重写的积分
SymPy fails to solve rewritten integral
当我使用函数 f2
时,积分被求解(相当快),但包含一些浮点常量。函数 f1
不使用浮点指数,但无法计算积分。它而是重新显示要求解的积分(经过很长时间)。
所以作为 SymPy
的新用户,我想知道 1) 我是否在 f1
中使用了一些错误的命令? 2) 是否有可能使 SymPy
的执行速度更快(因为它目前并没有真正与 Maple
的速度进行比较)。
from sympy import *
from IPython.display import display
init_printing(use_unicode=False, wrap_line=False, no_global=True)
def f1():
x, y = symbols('x y')
w, h = symbols('w h', real=True, nonzero=True, positive=True)
result = Integral((1/sqrt(((y-x)**2 + h**2)**3)), (x,0,w), (y,0,w))
display(result)
result = integrate((1/sqrt(((y-x)**2 + h**2)**3)), (x,0,w), (y,0,w))
display(result)
def f2():
x, y = symbols('x y')
w, h = symbols('w h', real=True, nonzero=True, positive=True)
result = Integral(1/(((y-x)**2 + h**2)**1.5), (x,0,w), (y,0,w))
display(result)
result = integrate(1/(((y-x)**2 + h**2)**1.5), (x,0,w), (y,0,w))
display(result)
Sympy 版本
>>> sympy.__version__
>>> '0.7.6.1'
你写的两个积分不完全一样。你可以做到
In [22]: integrate((1/sqrt(((y-x)**2 + h**2))**3), (x,0,w), (y,0,w))
Out[22]:
________
╱ 2
╱ w
2⋅ ╱ 1 + ──
╱ 2
╲╱ h 2
- ──────────────── + ─
h h
请注意 **3
位置的不同。原因是
In [25]: sqrt(x**3)
Out[25]:
____
╱ 3
╲╱ x
In [26]: sqrt(x)**3
Out[26]:
3/2
x
一般情况下两者不相等x
。对于您的情况,它们实际上是相等的,因为根中的表达式是正数,但 SymPy 没有注意到这一点。
当我使用函数 f2
时,积分被求解(相当快),但包含一些浮点常量。函数 f1
不使用浮点指数,但无法计算积分。它而是重新显示要求解的积分(经过很长时间)。
所以作为 SymPy
的新用户,我想知道 1) 我是否在 f1
中使用了一些错误的命令? 2) 是否有可能使 SymPy
的执行速度更快(因为它目前并没有真正与 Maple
的速度进行比较)。
from sympy import *
from IPython.display import display
init_printing(use_unicode=False, wrap_line=False, no_global=True)
def f1():
x, y = symbols('x y')
w, h = symbols('w h', real=True, nonzero=True, positive=True)
result = Integral((1/sqrt(((y-x)**2 + h**2)**3)), (x,0,w), (y,0,w))
display(result)
result = integrate((1/sqrt(((y-x)**2 + h**2)**3)), (x,0,w), (y,0,w))
display(result)
def f2():
x, y = symbols('x y')
w, h = symbols('w h', real=True, nonzero=True, positive=True)
result = Integral(1/(((y-x)**2 + h**2)**1.5), (x,0,w), (y,0,w))
display(result)
result = integrate(1/(((y-x)**2 + h**2)**1.5), (x,0,w), (y,0,w))
display(result)
Sympy 版本
>>> sympy.__version__
>>> '0.7.6.1'
你写的两个积分不完全一样。你可以做到
In [22]: integrate((1/sqrt(((y-x)**2 + h**2))**3), (x,0,w), (y,0,w))
Out[22]:
________
╱ 2
╱ w
2⋅ ╱ 1 + ──
╱ 2
╲╱ h 2
- ──────────────── + ─
h h
请注意 **3
位置的不同。原因是
In [25]: sqrt(x**3)
Out[25]:
____
╱ 3
╲╱ x
In [26]: sqrt(x)**3
Out[26]:
3/2
x
一般情况下两者不相等x
。对于您的情况,它们实际上是相等的,因为根中的表达式是正数,但 SymPy 没有注意到这一点。