本文整理汇总了Python中sympy.abc.x.evalf函数的典型用法代码示例。如果您正苦于以下问题:Python evalf函数的具体用法?Python evalf怎么用?Python evalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了evalf函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: test_subs
def test_subs():
from sympy import besseli
assert NS('besseli(-x, y) - besseli(x, y)', subs={x: 3.5, y: 20.0}) == \
'-4.92535585957223e-10'
assert NS('Piecewise((x, x>0)) + Piecewise((1-x, x>0))', subs={x: 0.1}) == \
'1.00000000000000'
raises(TypeError, lambda: x.evalf(subs=(x, 1)))
开发者ID:glyg,项目名称:sympy,代码行数:7,代码来源:test_evalf.py
示例3: 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
示例4: 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
示例5: 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"
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:Visheshk,项目名称:sympy,代码行数:24,代码来源:test_evalf.py
示例6: test_subs
def test_subs():
assert NS("besseli(-x, y) - besseli(x, y)", subs={x: 3.5, y: 20.0}) == "-4.92535585957223e-10"
assert NS("Piecewise((x, x>0)) + Piecewise((1-x, x>0))", subs={x: 0.1}) == "1.00000000000000"
raises(TypeError, lambda: x.evalf(subs=(x, 1)))
开发者ID:guanlongtianzi,项目名称:sympy,代码行数:4,代码来源:test_evalf.py
注:本文中的sympy.abc.x.evalf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论