本文整理汇总了Python中sympy.Integral.as_sum方法的典型用法代码示例。如果您正苦于以下问题:Python Integral.as_sum方法的具体用法?Python Integral.as_sum怎么用?Python Integral.as_sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Integral
的用法示例。
在下文中一共展示了Integral.as_sum方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_as_sum_raises
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_raises():
e = Integral((x + y)**2, (x, 0, 1))
raises(ValueError, lambda: e.as_sum(-1))
raises(ValueError, lambda: e.as_sum(0))
raises(ValueError, lambda: Integral(x).as_sum(3))
raises(NotImplementedError, lambda: e.as_sum(oo))
raises(NotImplementedError, lambda: e.as_sum(3, method='xxxx2'))
示例2: test_as_sum_right
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_right():
e = Integral((x + y)**2, (x, 0, 1))
assert e.as_sum(1, method="right").expand() == 1 + 2*y + y**2
assert e.as_sum(2, method="right").expand() == S(5)/8 + 3*y/2 + y**2
assert e.as_sum(3, method="right").expand() == S(14)/27 + 4*y/3 + y**2
assert e.as_sum(4, method="right").expand() == S(15)/32 + 5*y/4 + y**2
assert e.as_sum(n, method="right").expand() == \
y**2 + y + S(1)/3 + y/n + 1/(2*n) + 1/(6*n**2)
示例3: test_as_sum_trapezoid
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_trapezoid():
e = Integral((x + y)**2, (x, 0, 1))
assert e.as_sum(1, method="trapezoid").expand() == y**2 + y + S(1)/2
assert e.as_sum(2, method="trapezoid").expand() == y**2 + y + S(3)/8
assert e.as_sum(3, method="trapezoid").expand() == y**2 + y + S(19)/54
assert e.as_sum(4, method="trapezoid").expand() == y**2 + y + S(11)/32
assert e.as_sum(n, method="trapezoid").expand() == \
y**2 + y + S(1)/3 + 1/(6*n**2)
assert Integral(sign(x), (x, 0, 1)).as_sum(1, 'trapezoid') == S(1)/2
示例4: test_as_sum_left
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_left():
e = Integral((x + y)**2, (x, 0, 1))
assert e.as_sum(1, method="left").expand() == y**2
assert e.as_sum(2, method="left").expand() == S(1)/8 + y/2 + y**2
assert e.as_sum(3, method="left").expand() == S(5)/27 + 2*y/3 + y**2
assert e.as_sum(4, method="left").expand() == S(7)/32 + 3*y/4 + y**2
assert e.as_sum(n, method="left").expand() == \
y**2 + y + S(1)/3 - y/n - 1/(2*n) + 1/(6*n**2)
assert e.as_sum(10, method="left", evaluate=False).has(Sum)
示例5: test_as_sum_midpoint2
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_midpoint2():
e = Integral((x + y)**2, (x, 0, 1))
n = Symbol('n', positive=True, integer=True)
assert e.as_sum(1, method="midpoint").expand() == S(1)/4 + y + y**2
assert e.as_sum(2, method="midpoint").expand() == S(5)/16 + y + y**2
assert e.as_sum(3, method="midpoint").expand() == S(35)/108 + y + y**2
assert e.as_sum(4, method="midpoint").expand() == S(21)/64 + y + y**2
assert e.as_sum(n, method="midpoint").expand() == \
y**2 + y + 1/3 - 1/(12*n**2)
示例6: test_as_sum_midpoint1
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_midpoint1():
e = Integral(sqrt(x ** 3 + 1), (x, 2, 10))
assert e.as_sum(1, method="midpoint") == 8 * sqrt(217)
assert e.as_sum(2, method="midpoint") == 4 * sqrt(65) + 12 * sqrt(57)
assert e.as_sum(3, method="midpoint") == 8 * sqrt(217) / 3 + 8 * sqrt(3081) / 27 + 8 * sqrt(52809) / 27
assert e.as_sum(4, method="midpoint") == 2 * sqrt(730) + 4 * sqrt(7) + 4 * sqrt(86) + 6 * sqrt(14)
assert abs(e.as_sum(4, method="midpoint").n() - e.n()) < 0.5
e = Integral(sqrt(x ** 3 + y ** 3), (x, 2, 10), (y, 0, 10))
raises(NotImplementedError, "e.as_sum(4)")
示例7: test_as_sum_midpoint1
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_midpoint1():
e = Integral(sqrt(x**3+1), (x, 2, 10))
assert e.as_sum(1, method="midpoint") == 8*217**(S(1)/2)
assert e.as_sum(2, method="midpoint") == 4*65**(S(1)/2) + 12*57**(S(1)/2)
assert e.as_sum(3, method="midpoint") == 8*217**(S(1)/2)/3 + \
8*3081**(S(1)/2)/27 + 8*52809**(S(1)/2)/27
assert e.as_sum(4, method="midpoint") == 2*730**(S(1)/2) + \
4*7**(S(1)/2) + 4*86**(S(1)/2) + 6*14**(S(1)/2)
assert abs(e.as_sum(4, method="midpoint").n() - e.n()) < 0.5
e = Integral(sqrt(x**3+y**3), (x, 2, 10), (y, 0, 10))
raises(NotImplementedError, "e.as_sum(4)")
示例8: test_as_sum_left
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_left():
e = Integral((x + y)**2, (x, 0, 1))
assert e.as_sum(1, method="left").expand() == y**2
assert e.as_sum(2, method="left").expand() == S(1)/8 + y/2 + y**2
assert e.as_sum(3, method="left").expand() == S(5)/27 + 2*y/3 + y**2
assert e.as_sum(4, method="left").expand() == S(7)/32 + 3*y/4 + y**2
示例9: test_as_sum_midpoint2
# 需要导入模块: from sympy import Integral [as 别名]
# 或者: from sympy.Integral import as_sum [as 别名]
def test_as_sum_midpoint2():
e = Integral((x + y)**2, (x, 0, 1))
assert e.as_sum(1, method="midpoint").expand() == S(1)/4 + y + y**2
assert e.as_sum(2, method="midpoint").expand() == S(5)/16 + y + y**2
assert e.as_sum(3, method="midpoint").expand() == S(35)/108 + y + y**2
assert e.as_sum(4, method="midpoint").expand() == S(21)/64 + y + y**2