• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sympy.Integral类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_transform

def test_transform():
    a = Integral(x**2+1, (x, -1, 2))
    assert a.doit() == a.transform(x, 3*x+1).doit()
    assert a.transform(x, 3*x+1).transform(x, 3*x+1, inverse=True) == a
    assert a.transform(x, 3*x+1, inverse=True).transform(x, 3*x+1) == a
    a = Integral(sin(1/x), (x, 0, 1))
    assert a.transform(x, 1/x) == Integral(sin(x)/x**2, (x, 1, oo))
    assert a.transform(x, 1/x).transform(x, 1/x) == a
    a = Integral(exp(-x**2), (x, -oo, oo))
    assert a.transform(x, 2*x) == Integral(2*exp(-4*x**2), (x, -oo, oo))
    raises(ValueError, "a.transform(x, 1/x)")
    raises(ValueError, "a.transform(x, 1/x)")
开发者ID:smichr,项目名称:sympy-live,代码行数:12,代码来源:test_integrals.py


示例17: test_subs5

def test_subs5():
    e = Integral(exp(-x**2), x)
    assert e.subs(x, 5) == e
    e = Integral(exp(-x**2), (x, -oo, oo))
    assert e.subs(x, 5) == e
    e = Integral(exp(-x**2+y), x)
    assert e.subs(x, 5) == e
    assert e.subs(y, 5) != e
    assert e.subs(y, 5) == Integral(exp(-x**2+5), x)
    e = Integral(exp(-x**2+y), (y, -oo, oo), (x, -oo, oo))
    assert e.subs(x, 5) == e
    assert e.subs(y, 5) == e
开发者ID:smichr,项目名称:sympy-live,代码行数:12,代码来源:test_integrals.py


示例18: __new__

 def __new__(cls, function, *limits, **assumptions):
     repl, limits = IndexedIntegral._indexed_process_limits(limits)
     function = sympify(function)
     function = function.xreplace(repl)
     obj = Integral.__new__(cls, function, *limits, **assumptions)
     obj._indexed_repl = repl
     obj._indexed_reverse_repl = dict((val, key) for key, val in repl.items())
     return obj
开发者ID:A-turing-machine,项目名称:sympy,代码行数:8,代码来源:indexed_integrals.py


示例19: test_as_sum_midpoint1

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


示例20: test_transform

def test_transform():
    a = Integral(x ** 2 + 1, (x, -1, 2))
    fx = x
    fy = 3 * y + 1
    assert a.doit() == a.transform(fx, fy).doit()
    assert a.transform(fx, fy).transform(fy, fx) == a
    fx = 3 * x + 1
    fy = y
    assert a.transform(fx, fy).transform(fy, fx) == a
    a = Integral(sin(1 / x), (x, 0, 1))
    assert a.transform(x, 1 / y) == Integral(sin(y) / y ** 2, (y, 1, oo))
    assert a.transform(x, 1 / y).transform(y, 1 / x) == a
    a = Integral(exp(-x ** 2), (x, -oo, oo))
    assert a.transform(x, 2 * y) == Integral(2 * exp(-4 * y ** 2), (y, -oo, oo))
    # < 3 arg limit handled properly
    assert Integral(x, x).transform(x, a * y).doit() == Integral(y * a ** 2, y).doit()
    _3 = S(3)
    assert Integral(x, (x, 0, -_3)).transform(x, 1 / y).doit() == Integral(-1 / x ** 3, (x, -oo, -1 / _3)).doit()
    assert Integral(x, (x, 0, _3)).transform(x, 1 / y) == Integral(y ** (-3), (y, 1 / _3, oo))
开发者ID:arunenigma,项目名称:sympy,代码行数:19,代码来源:test_integrals.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sympy.Interval类代码示例发布时间:2022-05-27
下一篇:
Python sympy.Integer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap