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


Python pi.evalf函数代码示例

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


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

示例1: test_Float

def test_Float():
    # NOTE prec is the whole number of decimal digits
    assert str(Float("1.23", prec=1 + 2)) == "1.23"
    assert str(Float("1.23456789", prec=1 + 8)) == "1.23456789"
    assert str(Float("1.234567890123456789", prec=1 + 18)) == "1.234567890123456789"
    assert str(pi.evalf(1 + 2)) == "3.14"
    assert str(pi.evalf(1 + 14)) == "3.14159265358979"
    assert str(pi.evalf(1 + 64)) == "3.1415926535897932384626433832795028841971693993751058209749445923"
开发者ID:abhishek070193,项目名称:sympy,代码行数:8,代码来源:test_str.py

示例2: test_Real

def test_Real():
    # NOTE prec is the whole number of decimal digits
    assert str(Real('1.23', prec=1+2))    == '1.23'
    assert str(Real('1.23456789', prec=1+8))  == '1.23456789'
    assert str(Real('1.234567890123456789', prec=1+18))    == '1.234567890123456789'
    assert str(pi.evalf(1+2))   == '3.14'
    assert str(pi.evalf(1+14))  == '3.14159265358979'
    assert str(pi.evalf(1+64))  == '3.1415926535897932384626433832795028841971693993751058209749445923'
开发者ID:bibile,项目名称:sympy,代码行数:8,代码来源:test_str.py

示例3: test_Float

def test_Float():
    # NOTE prec is the whole number of decimal digits
    assert str(Float('1.23', prec=1+2))    == '1.23'
    assert str(Float('1.23456789', prec=1+8))  == '1.23456789'
    assert str(Float('1.234567890123456789', prec=1+18))    == '1.234567890123456789'
    assert str(pi.evalf(1+2))   == '3.14'
    assert str(pi.evalf(1+14))  == '3.14159265358979'
    assert str(pi.evalf(1+64))  == '3.1415926535897932384626433832795028841971693993751058209749445923'
    assert str(pi.round(-1)) == '0.'
    assert str((pi**400 - (pi**400).round(1)).n(2)) == '-0.e+88'
开发者ID:dyao-vu,项目名称:meta-core,代码行数:10,代码来源:test_str.py

示例4: test_Float

def test_Float():
    # NOTE prec is the whole number of decimal digits
    assert str(Float("1.23", prec=1 + 2)) == "1.23"
    assert str(Float("1.23456789", prec=1 + 8)) == "1.23456789"
    assert str(Float("1.234567890123456789", prec=1 + 18)) == "1.234567890123456789"
    assert str(pi.evalf(1 + 2)) == "3.14"
    assert str(pi.evalf(1 + 14)) == "3.14159265358979"
    assert str(pi.evalf(1 + 64)) == ("3.141592653589793238462643383279" "5028841971693993751058209749445923")
    assert str(pi.round(-1)) == "0."
    assert str((pi ** 400 - (pi ** 400).round(1)).n(2)) == "-0.e+88"
开发者ID:gilbertgede,项目名称:sympy,代码行数:10,代码来源:test_str.py

示例5: test_fcode_NumberSymbol

def test_fcode_NumberSymbol():
    assert fcode(Catalan) == '      parameter (Catalan = 0.915965594177219)\n      Catalan'
    assert fcode(EulerGamma) == '      parameter (EulerGamma = 0.577215664901533)\n      EulerGamma'
    assert fcode(E) == '      parameter (E = 2.71828182845905)\n      E'
    assert fcode(GoldenRatio) == '      parameter (GoldenRatio = 1.61803398874989)\n      GoldenRatio'
    assert fcode(pi) == '      parameter (pi = 3.14159265358979)\n      pi'
    assert fcode(pi,precision=5) == '      parameter (pi = 3.1416)\n      pi'
    assert fcode(Catalan,human=False) == ([('Catalan', Catalan.evalf(15))], set([]), '      Catalan')
    assert fcode(EulerGamma,human=False) == ([('EulerGamma', EulerGamma.evalf(15))], set([]), '      EulerGamma')
    assert fcode(E,human=False) == ([('E', E.evalf(15))], set([]), '      E')
    assert fcode(GoldenRatio,human=False) == ([('GoldenRatio', GoldenRatio.evalf(15))], set([]), '      GoldenRatio')
    assert fcode(pi,human=False) == ([('pi', pi.evalf(15))], set([]), '      pi')
    assert fcode(pi,precision=5,human=False) == ([('pi', pi.evalf(5))], set([]), '      pi')
开发者ID:tovrstra,项目名称:sympy,代码行数:13,代码来源:test_fcode.py

示例6: test_fcode_NumberSymbol

def test_fcode_NumberSymbol():
    p = FCodePrinter()
    assert fcode(Catalan) == '      parameter (Catalan = 0.915965594177219d0)\n      Catalan'
    assert fcode(EulerGamma) == '      parameter (EulerGamma = 0.577215664901533d0)\n      EulerGamma'
    assert fcode(E) == '      parameter (E = 2.71828182845905d0)\n      E'
    assert fcode(GoldenRatio) == '      parameter (GoldenRatio = 1.61803398874989d0)\n      GoldenRatio'
    assert fcode(pi) == '      parameter (pi = 3.14159265358979d0)\n      pi'
    assert fcode(pi,precision=5) == '      parameter (pi = 3.1416d0)\n      pi'
    assert fcode(Catalan,human=False) == (set([(Catalan, p._print(Catalan.evalf(15)))]), set([]), '      Catalan')
    assert fcode(EulerGamma,human=False) == (set([(EulerGamma, p._print(EulerGamma.evalf(15)))]), set([]), '      EulerGamma')
    assert fcode(E,human=False) == (set([(E, p._print(E.evalf(15)))]), set([]), '      E')
    assert fcode(GoldenRatio,human=False) == (set([(GoldenRatio, p._print(GoldenRatio.evalf(15)))]), set([]), '      GoldenRatio')
    assert fcode(pi,human=False) == (set([(pi, p._print(pi.evalf(15)))]), set([]), '      pi')
    assert fcode(pi,precision=5,human=False) == (set([(pi, p._print(pi.evalf(5)))]), set([]), '      pi')
开发者ID:Jerryy,项目名称:sympy,代码行数:14,代码来源:test_fcode.py

示例7: test_Float

def test_Float():
    # NOTE dps is the whole number of decimal digits
    assert str(Float('1.23', dps=1 + 2)) == '1.23'
    assert str(Float('1.23456789', dps=1 + 8)) == '1.23456789'
    assert str(
        Float('1.234567890123456789', dps=1 + 18)) == '1.234567890123456789'
    assert str(pi.evalf(1 + 2)) == '3.14'
    assert str(pi.evalf(1 + 14)) == '3.14159265358979'
    assert str(pi.evalf(1 + 64)) == ('3.141592653589793238462643383279'
                                     '5028841971693993751058209749445923')
    assert str(pi.round(-1)) == '0.'
    assert str((pi**400 - (pi**400).round(1)).n(2)) == '-0.e+88'
    assert str(Float(S.Infinity)) == 'inf'
    assert str(Float(S.NegativeInfinity)) == '-inf'
开发者ID:Lenqth,项目名称:sympy,代码行数:14,代码来源:test_str.py

示例8: test_evalf_bugs

def test_evalf_bugs():
    assert NS(sin(1)+exp(-10**10),10) == NS(sin(1),10)
    assert NS(exp(10**10)+sin(1),10) == NS(exp(10**10),10)
    assert NS('log(1+1/10**50)',20) == '1.0000000000000000000e-50'
    assert NS('log(10**100,10)',10) == '100.0000000'
    assert NS('log(2)',10) == '0.6931471806'
    assert NS('(sin(x)-x)/x**3', 15, subs={x:'1/10**50'}) == '-0.166666666666667'
    assert NS(sin(1)+Rational(1,10**100)*I,15) == '0.841470984807897 + 1.00000000000000e-100*I'
    assert x.evalf() == x
    assert NS((1+I)**2*I, 6) == '-2.00000'
    d={n: (-1)**Rational(6,7), y: (-1)**Rational(4,7), x: (-1)**Rational(2,7)}
    assert NS((x*(1+y*(1 + n))).subs(d).evalf(),6) == '0.346011 + 0.433884*I'
    assert NS(((-I-sqrt(2)*I)**2).evalf()) == '-5.82842712474619'
    assert NS((1+I)**2*I,15) == '-2.00000000000000'
    #1659 (1/2):
    assert NS(pi.evalf(69) - pi) == '-4.43863937855894e-71'
    #1659 (2/2): With the bug present, this still only fails if the
    # terms are in the order given here. This is not generally the case,
    # because the order depends on the hashes of the terms.
    assert NS(20 - 5008329267844*n**25 - 477638700*n**37 - 19*n,
              subs={n:.01}) == '19.8100000000000'
    assert NS(((x - 1)*((1 - x))**1000).n()) == '(-x + 1.00000000000000)**1000*(x - 1.00000000000000)'
    assert NS((-x).n()) == '-x'
    assert NS((-2*x).n()) == '-2.00000000000000*x'
    assert NS((-2*x*y).n()) == '-2.00000000000000*x*y'
开发者ID:vipulnsward,项目名称:sympy,代码行数:25,代码来源:test_evalf.py

示例9: test_nsolve

def test_nsolve():
    # onedimensional
    from sympy import Symbol, sin, pi
    x = Symbol('x')
    assert nsolve(sin(x), 2) - pi.evalf() < 1e-16
    assert nsolve(Eq(2*x, 2), x, -10) == nsolve(2*x - 2, -10)
    # multidimensional
    x1 = Symbol('x1')
    x2 = Symbol('x2')
    f1 = 3 * x1**2 - 2 * x2**2 - 1
    f2 = x1**2 - 2 * x1 + x2**2 + 2 * x2 - 8
    f = Matrix((f1, f2)).T
    F = lambdify((x1, x2), f.T, modules='mpmath')
    for x0 in [(-1, 1), (1, -2), (4, 4), (-4, -4)]:
        x = nsolve(f, (x1, x2), x0, tol=1.e-8)
        assert mnorm(F(*x),1) <= 1.e-10
    # The Chinese mathematician Zhu Shijie was the very first to solve this
    # nonlinear system 700 years ago (z was added to make it 3-dimensional)
    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')
    f1 = -x + 2*y
    f2 = (x**2 + x*(y**2 - 2) - 4*y)  /  (x + 4)
    f3 = sqrt(x**2 + y**2)*z
    f = Matrix((f1, f2, f3)).T
    F = lambdify((x,  y,  z), f.T, modules='mpmath')
    def getroot(x0):
        root = nsolve((f1,  f2,  f3), (x,  y,  z), x0)
        assert mnorm(F(*root),1) <= 1.e-8
        return root
    assert map(round,  getroot((1,  1,  1))) == [2.0,  1.0,  0.0]
开发者ID:cran,项目名称:rSymPy,代码行数:31,代码来源:test_numeric.py

示例10: test_evalf_bugs

def test_evalf_bugs():
    assert NS(sin(1) + exp(-10**10), 10) == NS(sin(1), 10)
    assert NS(exp(10**10) + sin(1), 10) == NS(exp(10**10), 10)
    assert NS('log(1+1/10**50)', 20) == '1.0000000000000000000e-50'
    assert NS('log(10**100,10)', 10) == '100.0000000'
    assert NS('log(2)', 10) == '0.6931471806'
    assert NS(
        '(sin(x)-x)/x**3', 15, subs={x: '1/10**50'}) == '-0.166666666666667'
    assert NS(sin(1) + Rational(
        1, 10**100)*I, 15) == '0.841470984807897 + 1.00000000000000e-100*I'
    assert x.evalf() == x
    assert NS((1 + I)**2*I, 6) == '-2.00000'
    d = {n: (
        -1)**Rational(6, 7), y: (-1)**Rational(4, 7), x: (-1)**Rational(2, 7)}
    assert NS((x*(1 + y*(1 + n))).subs(d).evalf(), 6) == '0.346011 + 0.433884*I'
    assert NS(((-I - sqrt(2)*I)**2).evalf()) == '-5.82842712474619'
    assert NS((1 + I)**2*I, 15) == '-2.00000000000000'
    # issue 4758 (1/2):
    assert NS(pi.evalf(69) - pi) == '-4.43863937855894e-71'
    # issue 4758 (2/2): With the bug present, this still only fails if the
    # terms are in the order given here. This is not generally the case,
    # because the order depends on the hashes of the terms.
    assert NS(20 - 5008329267844*n**25 - 477638700*n**37 - 19*n,
              subs={n: .01}) == '19.8100000000000'
    assert NS(((x - 1)*((1 - x))**1000).n()
              ) == '(-x + 1.00000000000000)**1000*(x - 1.00000000000000)'
    assert NS((-x).n()) == '-x'
    assert NS((-2*x).n()) == '-2.00000000000000*x'
    assert NS((-2*x*y).n()) == '-2.00000000000000*x*y'
    assert cos(x).n(subs={x: 1+I}) == cos(x).subs(x, 1+I).n()
    # issue 6660. Also NaN != mpmath.nan
    # In this order:
    # 0*nan, 0/nan, 0*inf, 0/inf
    # 0+nan, 0-nan, 0+inf, 0-inf
    # >>> n = Some Number
    # n*nan, n/nan, n*inf, n/inf
    # n+nan, n-nan, n+inf, n-inf
    assert (0*sin(oo)).n() == S.Zero
    assert (0/sin(oo)).n() == S.Zero
    assert (0*E**(oo)).n() == S.NaN
    assert (0/E**(oo)).n() == S.Zero

    assert (0+sin(oo)).n() == S.NaN
    assert (0-sin(oo)).n() == S.NaN
    assert (0+E**(oo)).n() == S.Infinity
    assert (0-E**(oo)).n() == S.NegativeInfinity

    assert (5*sin(oo)).n() == S.NaN
    assert (5/sin(oo)).n() == S.NaN
    assert (5*E**(oo)).n() == S.Infinity
    assert (5/E**(oo)).n() == S.Zero

    assert (5+sin(oo)).n() == S.NaN
    assert (5-sin(oo)).n() == S.NaN
    assert (5+E**(oo)).n() == S.Infinity
    assert (5-E**(oo)).n() == S.NegativeInfinity

    #issue 7416
    assert as_mpmath(0.0, 10, {'chop': True}) == 0
开发者ID:EuanFree,项目名称:sympy,代码行数:59,代码来源:test_evalf.py

示例11: test_issue1512

def test_issue1512():
    assert abs(pi._evalf(50) - 3.14159265358979) < 1e-10
    assert abs(E._evalf(50) - 2.71828182845905) < 1e-10
    assert abs(Catalan._evalf(50) - 0.915965594177219) < 1e-10
    assert abs(EulerGamma._evalf(50) - 0.577215664901533) < 1e-10
    assert abs(GoldenRatio._evalf(50) - 1.61803398874989) < 1e-10
    x = Symbol("x")
    assert (pi+x).evalf() == pi.evalf()+x
    assert (E+x).evalf() == E.evalf()+x
    assert (Catalan+x).evalf() == Catalan.evalf()+x
    assert (EulerGamma+x).evalf() == EulerGamma.evalf()+x
    assert (GoldenRatio+x).evalf() == GoldenRatio.evalf()+x
开发者ID:101man,项目名称:sympy,代码行数:12,代码来源:test_numbers.py

示例12: test_fcode_NumberSymbol

def test_fcode_NumberSymbol():
    prec = 17
    p = FCodePrinter()
    assert fcode(Catalan) == '      parameter (Catalan = %sd0)\n      Catalan' % Catalan.evalf(prec)
    assert fcode(EulerGamma) == '      parameter (EulerGamma = %sd0)\n      EulerGamma' % EulerGamma.evalf(prec)
    assert fcode(E) == '      parameter (E = %sd0)\n      E' % E.evalf(prec)
    assert fcode(GoldenRatio) == '      parameter (GoldenRatio = %sd0)\n      GoldenRatio' % GoldenRatio.evalf(prec)
    assert fcode(pi) == '      parameter (pi = %sd0)\n      pi' % pi.evalf(prec)
    assert fcode(
        pi, precision=5) == '      parameter (pi = %sd0)\n      pi' % pi.evalf(5)
    assert fcode(Catalan, human=False) == (set(
        [(Catalan, p._print(Catalan.evalf(prec)))]), set([]), '      Catalan')
    assert fcode(EulerGamma, human=False) == (set([(EulerGamma, p._print(
        EulerGamma.evalf(prec)))]), set([]), '      EulerGamma')
    assert fcode(E, human=False) == (
        set([(E, p._print(E.evalf(prec)))]), set([]), '      E')
    assert fcode(GoldenRatio, human=False) == (set([(GoldenRatio, p._print(
        GoldenRatio.evalf(prec)))]), set([]), '      GoldenRatio')
    assert fcode(pi, human=False) == (
        set([(pi, p._print(pi.evalf(prec)))]), set([]), '      pi')
    assert fcode(pi, precision=5, human=False) == (
        set([(pi, p._print(pi.evalf(5)))]), set([]), '      pi')
开发者ID:normalhuman,项目名称:sympy,代码行数:22,代码来源:test_fcode.py

示例13: test_evalf_bugs

def test_evalf_bugs():
    assert NS(sin(1) + exp(-10 ** 10), 10) == NS(sin(1), 10)
    assert NS(exp(10 ** 10) + sin(1), 10) == NS(exp(10 ** 10), 10)
    assert NS("log(1+1/10**50)", 20) == "1.0000000000000000000e-50"
    assert NS("log(10**100,10)", 10) == "100.0000000"
    assert NS("log(2)", 10) == "0.6931471806"
    assert NS("(sin(x)-x)/x**3", 15, subs={x: "1/10**50"}) == "-0.166666666666667"
    assert NS(sin(1) + Rational(1, 10 ** 100) * I, 15) == "0.841470984807897 + 1.00000000000000e-100*I"
    assert x.evalf() == x
    assert NS((1 + I) ** 2 * I, 6) == "-2.00000"
    d = {n: (-1) ** Rational(6, 7), y: (-1) ** Rational(4, 7), x: (-1) ** Rational(2, 7)}
    assert NS((x * (1 + y * (1 + n))).subs(d).evalf(), 6) == "0.346011 + 0.433884*I"
    assert NS(((-I - sqrt(2) * I) ** 2).evalf()) == "-5.82842712474619"
    assert NS((1 + I) ** 2 * I, 15) == "-2.00000000000000"
    # 1659 (1/2):
    assert NS(pi.evalf(69) - pi) == "-4.43863937855894e-71"
    # 1659 (2/2): With the bug present, this still only fails if the
    # terms are in the order given here. This is not generally the case,
    # because the order depends on the hashes of the terms.
    assert NS(20 - 5008329267844 * n ** 25 - 477638700 * n ** 37 - 19 * n, subs={n: 0.01}) == "19.8100000000000"
    assert NS(((x - 1) * ((1 - x)) ** 1000).n()) == "(-x + 1.00000000000000)**1000*(x - 1.00000000000000)"
    assert NS((-x).n()) == "-x"
    assert NS((-2 * x).n()) == "-2.00000000000000*x"
    assert NS((-2 * x * y).n()) == "-2.00000000000000*x*y"
    assert cos(x).n(subs={x: 1 + I}) == cos(x).subs(x, 1 + I).n()
    # 3561. Also NaN != mpmath.nan
    # In this order:
    # 0*nan, 0/nan, 0*inf, 0/inf
    # 0+nan, 0-nan, 0+inf, 0-inf
    # >>> n = Some Number
    # n*nan, n/nan, n*inf, n/inf
    # n+nan, n-nan, n+inf, n-inf
    assert (0 * sin(oo)).n() == S.Zero
    assert (0 / sin(oo)).n() == S.Zero
    assert (0 * E ** (oo)).n() == S.NaN
    assert (0 / E ** (oo)).n() == S.Zero

    assert (0 + sin(oo)).n() == S.NaN
    assert (0 - sin(oo)).n() == S.NaN
    assert (0 + E ** (oo)).n() == S.Infinity
    assert (0 - E ** (oo)).n() == S.NegativeInfinity

    assert (5 * sin(oo)).n() == S.NaN
    assert (5 / sin(oo)).n() == S.NaN
    assert (5 * E ** (oo)).n() == S.Infinity
    assert (5 / E ** (oo)).n() == S.Zero

    assert (5 + sin(oo)).n() == S.NaN
    assert (5 - sin(oo)).n() == S.NaN
    assert (5 + E ** (oo)).n() == S.Infinity
    assert (5 - E ** (oo)).n() == S.NegativeInfinity
开发者ID:ottersmh,项目名称:sympy,代码行数:51,代码来源:test_evalf.py

示例14: test_inline_function

def test_inline_function():
    x = symbols('x')
    g = implemented_function('g', Lambda(x, 2*x))
    assert fcode(g(x)) == "      2*x"
    g = implemented_function('g', Lambda(x, 2*pi/x))
    assert fcode(g(x)) == (
        "      parameter (pi = %sd0)\n"
        "      2*pi/x"
    ) % pi.evalf(17)
    A = IndexedBase('A')
    i = Idx('i', symbols('n', integer=True))
    g = implemented_function('g', Lambda(x, x*(1 + x)*(2 + x)))
    assert fcode(g(A[i]), assign_to=A[i]) == (
        "      do i = 1, n\n"
        "         A(i) = (A(i) + 1)*(A(i) + 2)*A(i)\n"
        "      end do"
    )
开发者ID:normalhuman,项目名称:sympy,代码行数:17,代码来源:test_fcode.py

示例15: test_evalf_bugs

def test_evalf_bugs():
    assert NS(sin(1) + exp(-10 ** 10), 10) == NS(sin(1), 10)
    assert NS(exp(10 ** 10) + sin(1), 10) == NS(exp(10 ** 10), 10)
    assert NS("log(1+1/10**50)", 20) == "1.0000000000000000000e-50"
    assert NS("log(10**100,10)", 10) == "100.0000000"
    assert NS("log(2)", 10) == "0.6931471806"
    assert NS("(sin(x)-x)/x**3", 15, subs={x: "1/10**50"}) == "-0.166666666666667"
    assert NS(sin(1) + Rational(1, 10 ** 100) * I, 15) == "0.841470984807897 + 1.00000000000000e-100*I"
    assert x.evalf() == x
    assert NS((1 + I) ** 2 * I, 6) == "-2.00000 + 2.32831e-10*I"
    d = {n: (-1) ** Rational(6, 7), y: (-1) ** Rational(4, 7), x: (-1) ** Rational(2, 7)}
    assert NS((x * (1 + y * (1 + n))).subs(d).evalf(), 6) == "0.346011 + 0.433884*I"
    assert NS(((-I - sqrt(2) * I) ** 2).evalf()) == "-5.82842712474619"
    assert NS((1 + I) ** 2 * I, 15) == "-2.00000000000000 + 2.16840434497101e-19*I"
    # 1659 (1/2):
    assert NS(pi.evalf(69) - pi) == "-4.43863937855894e-71"
    # 1659 (2/2): With the bug present, this still only fails if the
    # terms are in the order given here. This is not generally the case,
    # because the order depends on the hashes of the terms.
    assert NS(20 - 5008329267844 * n ** 25 - 477638700 * n ** 37 - 19 * n, subs={n: 0.01}) == "19.8100000000000"
开发者ID:rainly,项目名称:sympy,代码行数:20,代码来源:test_evalf.py


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