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


Python sympy.limit函数代码示例

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


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

示例1: test_exponential

def test_exponential():
    n = Symbol('n')
    x = Symbol('x', real=True)
    assert limit((1+x/n)**n,n,oo) == exp(x)
    assert limit((1+x/(2*n))**n,n,oo) == exp(x/2)
    assert limit((1+x/(2*n+1))**n,n,oo) == exp(x/2)
    assert limit(((x-1)/(x+1))**x,x,oo) == exp(-2)
开发者ID:Enchanter12,项目名称:sympy,代码行数:7,代码来源:test_limits.py

示例2: _calc_horizontal_asym

 def _calc_horizontal_asym(self, q, expr):
     # if the limit(x->+oo)=a, or limit(x->-oo)=a, then
     # y=a is a horizontal asymptote.
     debug('Looking for horizontal asymptotes for: ' +
           str(expr))
     try:
         poi = []
         lr = limit(expr, 'x', 'oo')
         ll = limit(expr, 'x', '-oo')
         if 'oo' not in str(lr):
             debug('Found a horizontal asymptote at y=' +
                   str(lr) + ' as x->+oo.')
             poi.append(POI(0, lr, 7))
         if 'oo' not in str(ll):
             if ll == lr:
                 debug('Same horizontal asymptote as x->-oo.')
             else:
                 debug('Found a horizontal asymptote at y=' +
                       str(ll) + ' as x->-oo')
                 poi.append(POI(0, ll, 7))
         q.put(poi)
     except NotImplementedError:
         debug('NotImplementedError for finding limit of "' +
               str(expr) + '"')
     if poi == []:
         debug('Done calculating horizontal asymptotes.' +
               'None found.')
     else:
         debug('Done calculating horizontal asymptotes')
开发者ID:gapan,项目名称:functionplot,代码行数:29,代码来源:Function.py

示例3: _code_val

    def _code_val(x):
        "Génère le code correspondant à une valeur `x` remarquable."
        if x in ens_def:
            # On calcule simplement f(x).
            fx = nice_str2(expr.subs(var, x))
        else:
            # x est une valeur interdite ou -oo ou +oo.
            symb = ('|' if x not in (-oo, oo) else '')
            gauche = droite = ''
            if limites:
                # On calcule la limite à gauche et/ou à droite.
                if x in sups:
                    gauche = nice_str2(limit(expr, var, x, dir = '-'))
                if x in infs:
                    droite = nice_str2(limit(expr, var, x, dir = '+'))
            fx = '%s%s%s' % (gauche, symb, droite)

        # Affichage de f'(x) (seulement si f'(x)=0 ou f'(x) non défini).
        if x in (-oo, oo):
            dfx = ''
        elif x in ens_def_df: # `oo in ens_def_df` plante actuellement (05/2014)
            dfx = ('0' if abs(df.subs(var, x).evalf()) < param.tolerance else '')
        else:
            dfx = '|'
        if dfx and derivee:
            return '(%s;%s;%s)' % (nice_str2(x), fx, dfx)
        else:
            return '(%s;%s)' % (nice_str2(x), fx)
开发者ID:wxgeo,项目名称:geophar,代码行数:28,代码来源:tabvar.py

示例4: residue

    def residue(self, pole, poles):

        expr, var = self.expr, self.var

        # Remove pole from list of poles; sym.cancel
        # doesn't always work, for example, for complex poles.
        poles2 = poles.copy()
        poles2[pole] -= 1

        numer, denom = expr.as_numer_denom()
        D = sym.Poly(denom, var)
        K = D.LC()

        D = [(var - p) ** poles2[p] for p in poles2]
        denom = sym.Mul(K, *D)

        d = sym.limit(denom, var, pole)

        if d != 0:
            tmp = numer / denom
            return sym.limit(tmp, var, pole)

        print("Trying l'hopital's rule")
        tmp = numer / denom
        tmp = sym.diff(tmp, var)

        return sym.limit(tmp, var, pole)
开发者ID:bcbnz,项目名称:lcapy,代码行数:27,代码来源:core.py

示例5: test_limit_seq

def test_limit_seq():
    assert limit(Sum(1/x, (x, 1, y)) - log(y), y, oo) == EulerGamma
    assert limit(Sum(1/x, (x, 1, y)) - 1/y, y, oo) == S.Infinity
    assert (limit(binomial(2*x, x) / Sum(binomial(2*y, y), (y, 1, x)), x, oo) ==
            S(3) / 4)
    assert (limit(Sum(y**2 * Sum(2**z/z, (z, 1, y)), (y, 1, x)) /
                  (2**x*x), x, oo) == 4)
开发者ID:Davidjohnwilson,项目名称:sympy,代码行数:7,代码来源:test_limits.py

示例6: test_Limits_simple_4a

def test_Limits_simple_4a():
    a = Symbol('a', real=True)
    assert limit((sqrt(x)-sqrt(a))/(x-a),x,a)==1/(2*sqrt(a))  #Primer 5
    assert limit((sqrt(x)-1)/(sqrt3(x)-1),x,1)==Rational(3)/2  #205
    assert limit((sqrt(1+x)-sqrt(1-x))/x,x,0)==1  #207
    assert limit(sqrt(x**2-5*x+6)-x,x,oo)==-Rational(5)/2  #213
    assert limit(x*(sqrt(x**2+1)-x),x,oo)==Rational(1)/2  #214
开发者ID:certik,项目名称:sympy-oldcore,代码行数:7,代码来源:test_demidovich.py

示例7: test_erf

def test_erf():
    assert erf(nan) == nan

    assert erf(oo) == 1
    assert erf(-oo) == -1

    assert erf(0) == 0

    assert erf(I*oo) == oo*I
    assert erf(-I*oo) == -oo*I

    assert erf(-2) == -erf(2)
    assert erf(-x*y) == -erf(x*y)
    assert erf(-x - y) == -erf(x + y)

    assert erf(I).is_real == False
    assert erf(0).is_real == True

    assert conjugate(erf(z)) == erf(conjugate(z))

    assert erf(x).as_leading_term(x) == x
    assert erf(1/x).as_leading_term(x) == erf(1/x)

    assert erf(z).rewrite('uppergamma') == sqrt(z**2)*erf(sqrt(z**2))/z

    assert limit(exp(x)*exp(x**2)*(erf(x+1/exp(x))-erf(x)), x, oo) == 2/sqrt(pi)
    assert limit((1-erf(z))*exp(z**2)*z, z, oo) == 1/sqrt(pi)
    assert limit((1-erf(x))*exp(x**2)*sqrt(pi)*x, x, oo) == 1
    assert limit(((1-erf(x))*exp(x**2)*sqrt(pi)*x-1)*2*x**2, x, oo) == -1

    raises(ArgumentIndexError, 'erf(x).fdiff(2)')
开发者ID:abhishek070193,项目名称:sympy,代码行数:31,代码来源:test_error_functions.py

示例8: codomain_interval

    def codomain_interval(f, set_val, *sym):
        symb = sym[0]
        df1 = diff(f, symb)
        df2 = diff(df1, symb)
        der_zero = solveset(df1, symb, domain=S.Reals)
        der_zero_in_dom = closure_handle(set_val, der_zero)

        local_maxima = set()
        local_minima = set()
        start_val = limit(f, symb, set_val.start)
        end_val = limit(f, symb, set_val.end, '-')

        if start_val is S.Infinity or end_val is S.Infinity:
            local_maxima = set([(oo, True)])
        elif start_val is S.NegativeInfinity or end_val is S.NegativeInfinity:
            local_minima = set([(-oo, True)])

        if (not start_val.is_real) or (not end_val.is_real):
            raise ValueError('Function does not contain all points of %s '
                            'as its domain' % (domain))

        if local_maxima == set():
            if start_val > end_val:
                local_maxima = set([(start_val, set_val.left_open)])
            elif start_val < end_val:
                local_maxima = set([(end_val, set_val.right_open)])
            else:
                local_maxima = set([(start_val, set_val.left_open and set_val.right_open)])

        if local_minima == set():
            if start_val < end_val:
                local_minima = set([(start_val, set_val.left_open)])
            elif start_val > end_val:
                local_minima = set([(end_val, set_val.right_open)])
            else:
                local_minima = set([(start_val, set_val.left_open and set_val.right_open)])

        for i in der_zero_in_dom:
            exist = not i in set_val
            if df2.subs({symb: i}) < 0:
                local_maxima.add((f.subs({symb: i}), exist))
            elif df2.subs({symb: i}) > 0:
                local_minima.add((f.subs({symb: i}), exist))

        maximum = (-oo, True)
        minimum = (oo, True)

        for i in local_maxima:
            if i[0] > maximum[0]:
                maximum = i
            elif i[0] == maximum[0]:
                maximum = (maximum[0], i[1] and maximum[1])

        for i in local_minima:
            if i[0] < minimum[0]:
                minimum = i
            elif i[0] == minimum[0]:
                minimum = (minimum[0], i[1] and minimum[1])

        return Union(Interval(minimum[0], maximum[0], minimum[1], maximum[1]))
开发者ID:MechCoder,项目名称:sympy,代码行数:60,代码来源:codomain.py

示例9: _limit

def _limit(eq, *args, **kwargs):
    if isinstance(eq, sp.Eq):
        # The provided equation is an equality, so we need to process the limit
        # of each side independently.
        return sp.Eq(sp.limit(eq.lhs, *args, **kwargs),
                     sp.limit(eq.rhs, *args, **kwargs))
    else:
        return sp.limit(*args, **kwargs)
开发者ID:wheeler-microfluidics,项目名称:dmf-control-board-firmware,代码行数:8,代码来源:feedback.py

示例10: test_exponential

def test_exponential():
    n = Symbol("n")
    x = Symbol("x", real=True)
    assert limit((1 + x / n) ** n, n, oo) == exp(x)
    assert limit((1 + x / (2 * n)) ** n, n, oo) == exp(x / 2)
    assert limit((1 + x / (2 * n + 1)) ** n, n, oo) == exp(x / 2)
    assert limit(((x - 1) / (x + 1)) ** x, x, oo) == exp(-2)
    assert limit(1 + (1 + 1 / x) ** x, x, oo) == 1 + S.Exp1
开发者ID:Nitin216,项目名称:sympy,代码行数:8,代码来源:test_limits.py

示例11: test_f1a

def test_f1a():
    h = Symbol("h")
    #needs a special logic for deciding that sin(x) is bounded:
    assert limit(sin(x)/x,x,oo) == 0 #216b
    #needs a special logic for deciding that sin(x) is bounded:
    assert limit(x*sin(1/x),x,0) == 0 #227a
    #issue 409:
    assert limit((sin(2*x)/x)**(1+x),x,0) == 2 #Primer 7
    #issue 410:
    assert limit(((x-1)/(x+1))**x,x,oo) == exp(-2) #Primer 9
开发者ID:certik,项目名称:sympy-oldcore,代码行数:10,代码来源:test_demidovich.py

示例12: test_sympy

def test_sympy():
    x = Symbol('x', real = True)
    assert -oo < oo
    assert not(-1.5 < -oo)
    assert (1 - exp(x)).is_negative is None
    assert Matrix([[1, 2], [3, 4]])**Integer(2) == Matrix([[7, 10], [15, 22]])
    assertAlmostEqual(E._evalf(50), math.e)
    assert solve(1/x, x) == [] # issue 1694
    assert solve(-(1 + x)/(2 + x)**2 + 1/(2 + x), x) == [] # issue 1694
    assert limit(1 + 1/x, x, 0, dir='-') == -oo
    assert limit(1/x**2, x, 0, dir='-') == oo
    assert sympify(u'45') == 45 # issue 2508
开发者ID:Grahack,项目名称:geophar,代码行数:12,代码来源:test_sympy.py

示例13: test_erf

def test_erf():
    assert erf(nan) == nan

    assert erf(oo) == 1
    assert erf(-oo) == -1

    assert erf(0) == 0

    assert erf(I*oo) == oo*I
    assert erf(-I*oo) == -oo*I

    assert erf(-2) == -erf(2)
    assert erf(-x*y) == -erf(x*y)
    assert erf(-x - y) == -erf(x + y)

    assert erf(erfinv(x)) == x
    assert erf(erfcinv(x)) == 1 - x
    assert erf(erf2inv(0, x)) == x
    assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x

    assert erf(I).is_real is False
    assert erf(0).is_real is True

    assert conjugate(erf(z)) == erf(conjugate(z))

    assert erf(x).as_leading_term(x) == 2*x/sqrt(pi)
    assert erf(1/x).as_leading_term(x) == erf(1/x)

    assert erf(z).rewrite('uppergamma') == sqrt(z**2)*(1 - erfc(sqrt(z**2)))/z
    assert erf(z).rewrite('erfc') == S.One - erfc(z)
    assert erf(z).rewrite('erfi') == -I*erfi(I*z)
    assert erf(z).rewrite('fresnels') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
        I*fresnels(z*(1 - I)/sqrt(pi)))
    assert erf(z).rewrite('fresnelc') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
        I*fresnels(z*(1 - I)/sqrt(pi)))
    assert erf(z).rewrite('hyper') == 2*z*hyper([S.Half], [3*S.Half], -z**2)/sqrt(pi)
    assert erf(z).rewrite('meijerg') == z*meijerg([S.Half], [], [0], [-S.Half], z**2)/sqrt(pi)
    assert erf(z).rewrite('expint') == sqrt(z**2)/z - z*expint(S.Half, z**2)/sqrt(S.Pi)

    assert limit(exp(x)*exp(x**2)*(erf(x + 1/exp(x)) - erf(x)), x, oo) == \
        2/sqrt(pi)
    assert limit((1 - erf(z))*exp(z**2)*z, z, oo) == 1/sqrt(pi)
    assert limit((1 - erf(x))*exp(x**2)*sqrt(pi)*x, x, oo) == 1
    assert limit(((1 - erf(x))*exp(x**2)*sqrt(pi)*x - 1)*2*x**2, x, oo) == -1

    assert erf(x).as_real_imag() == \
        ((erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 +
         erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2,
         I*(erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) -
         erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))) *
         re(x)*Abs(im(x))/(2*im(x)*Abs(re(x)))))

    raises(ArgumentIndexError, lambda: erf(x).fdiff(2))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:53,代码来源:test_error_functions.py

示例14: test_issue_5172

def test_issue_5172():
    n = Symbol('n')
    r = Symbol('r', positive=True)
    c = Symbol('c')
    p = Symbol('p', positive=True)
    m = Symbol('m', negative=True)
    expr = ((2*n*(n - r + 1)/(n + r*(n - r + 1)))**c + \
        (r - 1)*(n*(n - r + 2)/(n + r*(n - r + 1)))**c - n)/(n**c - n)
    expr = expr.subs(c, c + 1)
    raises(NotImplementedError, lambda: limit(expr, n, oo))
    assert limit(expr.subs(c, m), n, oo) == 1
    assert limit(expr.subs(c, p), n, oo).simplify() == \
        (2**(p + 1) + r - 1)/(r + 1)**(p + 1)
开发者ID:AdrianPotter,项目名称:sympy,代码行数:13,代码来源:test_limits.py

示例15: test_issue_5183

def test_issue_5183():
    # using list(...) so py.test can recalculate values
    tests = list(cartes([x, -x], [-1, 1], [2, 3, Rational(1, 2), Rational(2, 3)], ["-", "+"]))
    results = (
        oo,
        oo,
        -oo,
        oo,
        -oo * I,
        oo,
        -oo * (-1) ** Rational(1, 3),
        oo,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        oo,
        oo,
        oo,
        -oo,
        oo,
        -oo * I,
        oo,
        -oo * (-1) ** Rational(1, 3),
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
    )
    assert len(tests) == len(results)
    for i, (args, res) in enumerate(zip(tests, results)):
        y, s, e, d = args
        eq = y ** (s * e)
        try:
            assert limit(eq, x, 0, dir=d) == res
        except AssertionError:
            if 0:  # change to 1 if you want to see the failing tests
                print()
                print(i, res, eq, d, limit(eq, x, 0, dir=d))
            else:
                assert None
开发者ID:Nitin216,项目名称:sympy,代码行数:49,代码来源:test_limits.py


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