当前位置: 首页>>代码示例>>Python>>正文


Python sympy.Integral类代码示例

本文整理汇总了Python中sympy.Integral的典型用法代码示例。如果您正苦于以下问题:Python Integral类的具体用法?Python Integral怎么用?Python Integral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Integral类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_expand_integral

def test_expand_integral():
    assert Integral(cos(x ** 2) * (sin(x ** 2) + 1), (x, 0, 1)).expand() == Integral(
        cos(x ** 2) * sin(x ** 2) + cos(x ** 2), (x, 0, 1)
    )
    assert Integral(cos(x ** 2) * (sin(x ** 2) + 1), x).expand() == Integral(cos(x ** 2) * sin(x ** 2) + cos(x ** 2), x)
    i = Integral(x, (x, 1, 2), (x, 1, 2))
    assert i._eval_expand_basic() == i
开发者ID:arunenigma,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例2: test_literal_evalf_is_number_is_zero_is_comparable

def test_literal_evalf_is_number_is_zero_is_comparable():
    from sympy.integrals.integrals import Integral
    from sympy.core.symbol import symbols
    from sympy.core.function import Function
    from sympy.functions.elementary.trigonometric import cos, sin
    x = symbols('x')
    f = Function('f')

    # issue 5033
    assert f.is_number is False
    # issue 6646
    assert f(1).is_number is False
    i = Integral(0, (x, x, x))
    # expressions that are symbolically 0 can be difficult to prove
    # so in case there is some easy way to know if something is 0
    # it should appear in the is_zero property for that object;
    # if is_zero is true evalf should always be able to compute that
    # zero
    assert i.n() == 0
    assert i.is_zero
    assert i.is_number is False
    assert i.evalf(2, strict=False) == 0

    # issue 10268
    n = sin(1)**2 + cos(1)**2 - 1
    assert n.is_comparable is False
    assert n.n(2).is_comparable is False
    assert n.n(2).n(2).is_comparable
开发者ID:gamechanger98,项目名称:sympy,代码行数:28,代码来源:test_basic.py

示例3: test_as_sum_raises

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'))
开发者ID:baoqchau,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例4: test_as_sum_right

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)
开发者ID:normalhuman,项目名称:sympy,代码行数:8,代码来源:test_integrals.py

示例5: test_doit

def test_doit():
    e = Integral(Integral(2*x), (x, 0, 1))
    assert e.doit() == Rational(1, 3)
    f = Function('f')
    # doesn't matter if the integral can't be performed
    assert Integral(f(x), (x, 1, 1)).doit() == 0
    # doesn't matter if the limits can't be evaluated
    assert Integral(0, (x, 1, Integral(f(x), x))).doit() == 0
开发者ID:silver1543,项目名称:sympy,代码行数:8,代码来源:test_integrals.py

示例6: test_subs7

def test_subs7():
    e = Integral(x, (x, 1, y), (y, 1, 2))
    assert e.subs({x: 1, y: 2}) == e
    e = Integral(sin(x) + sin(y), (x, sin(x), sin(y)),
                                  (y, 1, 2))
    assert e.subs(sin(y), 1) == e
    assert e.subs(sin(x), 1) == Integral(sin(x) + sin(y), (x, 1, sin(y)),
                                         (y, 1, 2))
开发者ID:baoqchau,项目名称:sympy,代码行数:8,代码来源:test_integrals.py

示例7: test_issue1566

def test_issue1566():
    # Allow only upper or lower limit evaluation
    e = Integral(x**2, (x, None, 1))
    f = Integral(x**2, (x, 1, None))
    assert e.doit() == Rational(1, 3)
    assert f.doit() == Rational(-1, 3)
    assert Integral(x*y, (x, None, y)).subs(y, t) == Integral(x*t, (x, None, t))
    assert Integral(x*y, (x, y, None)).subs(y, t) == Integral(x*t, (x, t, None))
开发者ID:KevinGoodsell,项目名称:sympy,代码行数:8,代码来源:test_integrals.py

示例8: test_as_sum_left

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)
开发者ID:normalhuman,项目名称:sympy,代码行数:9,代码来源:test_integrals.py

示例9: test_as_sum_trapezoid

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
开发者ID:normalhuman,项目名称:sympy,代码行数:9,代码来源:test_integrals.py

示例10: test_as_sum_midpoint2

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)
开发者ID:normalhuman,项目名称:sympy,代码行数:9,代码来源:test_integrals.py

示例11: test_doit

def test_doit():
    a = Integral(x**2, x)

    assert isinstance(a.doit(), Integral) == False

    assert isinstance(a.doit(integrals=True), Integral) == False
    assert isinstance(a.doit(integrals=False), Integral) == True

    assert (2*Integral(x, x)).doit() == x**2
开发者ID:qmattpap,项目名称:sympy,代码行数:9,代码来源:test_expr.py

示例12: test_is_zero

def test_is_zero():
    from sympy.abc import x, m, n
    assert Integral(0, (x, 1, x)).is_zero
    assert Integral(1, (x, 1, 1)).is_zero
    assert Integral(1, (x, 1, 2)).is_zero is False
    assert Integral(sin(m*x)*cos(n*x), (x, 0, 2*pi)).is_zero is None
    assert Integral(x, (m, 0)).is_zero
    assert Integral(x + 1/m, (m, 0)).is_zero is None
    i = Integral(m, (m, 1, exp(x)), (x, 0))
    assert i.is_zero is None and i.doit() == S(1)/4
    assert Integral(m, (x, 0), (m, 1, exp(x))).is_zero is True
开发者ID:B-Rich,项目名称:sympy,代码行数:11,代码来源:test_integrals.py

示例13: test_doit_integrals

def test_doit_integrals():
    e = Integral(Integral(2*x), (x, 0, 1))
    assert e.doit() == Rational(1, 3)
    assert e.doit(deep=False) == Rational(1, 3)
    f = Function('f')
    # doesn't matter if the integral can't be performed
    assert Integral(f(x), (x, 1, 1)).doit() == 0
    # doesn't matter if the limits can't be evaluated
    assert Integral(0, (x, 1, Integral(f(x), x))).doit() == 0
    assert Integral(x, (a, 0)).doit() == 0
    limits = ((a, 1, exp(x)), (x, 0))
    assert Integral(a, *limits).doit() == S(1)/4
    assert Integral(a, *list(reversed(limits))).doit() == 0
开发者ID:baoqchau,项目名称:sympy,代码行数:13,代码来源:test_integrals.py

示例14: test_issue1566

def test_issue1566():
    # Allow only upper or lower limit evaluation
    e = Integral(x**2, (x, None, 1))
    f = Integral(x**2, (x, 1, None))
    assert e.doit() == Rational(1, 3)
    assert f.doit() == Rational(-1, 3)
    assert Integral(x*y, (x, None, y)).subs(y, t) == Integral(x*t, (x, None, t))
    assert Integral(x*y, (x, y, None)).subs(y, t) == Integral(x*t, (x, t, None))
    #FIXME-py3k: This fails somewhere down the line with:
    #FIXME-py3k: TypeError: type Float doesn't define __round__ method
    assert integrate(x**2, (x, None, 1)) == Rational(1, 3)
    assert integrate(x**2, (x, 1, None)) == Rational(-1, 3)
    assert integrate("x**2", ("x", "1", None)) == Rational(-1, 3)
开发者ID:Grahack,项目名称:geophar,代码行数:13,代码来源:test_integrals.py

示例15: test_get_motion_methods

def test_get_motion_methods():
    # Initialization
    t = dynamicsymbols._t
    s1, s2, s3 = symbols("s1 s2 s3")
    S1, S2, S3 = symbols("S1 S2 S3")
    S4, S5, S6 = symbols("S4 S5 S6")
    t1, t2 = symbols("t1 t2")
    a, b, c = dynamicsymbols("a b c")
    ad, bd, cd = dynamicsymbols("a b c", 1)
    a2d, b2d, c2d = dynamicsymbols("a b c", 2)
    v0 = S1 * N.x + S2 * N.y + S3 * N.z
    v01 = S4 * N.x + S5 * N.y + S6 * N.z
    v1 = s1 * N.x + s2 * N.y + s3 * N.z
    v2 = a * N.x + b * N.y + c * N.z
    v2d = ad * N.x + bd * N.y + cd * N.z
    v2dd = a2d * N.x + b2d * N.y + c2d * N.z
    # Test position parameter
    assert get_motion_params(frame=N) == (0, 0, 0)
    assert get_motion_params(N, position=v1) == (0, 0, v1)
    assert get_motion_params(N, position=v2) == (v2dd, v2d, v2)
    # Test velocity parameter
    assert get_motion_params(N, velocity=v1) == (0, v1, v1 * t)
    assert get_motion_params(N, velocity=v1, position=v0, timevalue1=t1) == (0, v1, v0 + v1 * (t - t1))
    assert get_motion_params(N, velocity=v1, position=v2, timevalue1=t1) == (0, v1, v1 * t - v1 * t1 + v2.subs(t, t1))
    integral_vector = Integral(a, t) * N.x + Integral(b, t) * N.y + Integral(c, t) * N.z
    assert get_motion_params(N, velocity=v2, position=v0, timevalue1=t1) == (
        v2d,
        v2,
        v0 + integral_vector - integral_vector.subs(t, t1),
    )
    # Test acceleration parameter
    assert get_motion_params(N, acceleration=v1) == (v1, v1 * t, v1 * t ** 2 / 2)
    assert get_motion_params(N, acceleration=v1, velocity=v0, position=v2, timevalue1=t1, timevalue2=t2) == (
        v1,
        (v0 + v1 * t - v1 * t2),
        -v0 * t1 + v1 * t ** 2 / 2 + v1 * t2 * t1 - v1 * t1 ** 2 / 2 + t * (v0 - v1 * t2) + v2.subs(t, t1),
    )
    assert get_motion_params(N, acceleration=v1, velocity=v0, position=v01, timevalue1=t1, timevalue2=t2) == (
        v1,
        v0 + v1 * t - v1 * t2,
        -v0 * t1 + v01 + v1 * t ** 2 / 2 + v1 * t2 * t1 - v1 * t1 ** 2 / 2 + t * (v0 - v1 * t2),
    )
    i = Integral(a, t)
    i_sub = i.subs(t, t2)
    assert get_motion_params(
        N, acceleration=a * N.x, velocity=S1 * N.x, position=S2 * N.x, timevalue1=t1, timevalue2=t2
    ) == (
        a * N.x,
        (S1 + i - i_sub) * N.x,
        (S2 + Integral(S1 - t * (a.subs(t, t2)) + i, t) - Integral(S1 - t1 * (a.subs(t, t2)) + i.subs(t, t1), t)) * N.x,
    )
开发者ID:rohith2506,项目名称:sympy,代码行数:51,代码来源:test_functions.py


注:本文中的sympy.Integral类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。