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


Python mpmath.mpf函数代码示例

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


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

示例1: test_mpmath_lambda

def test_mpmath_lambda():
    mpmath.mp.dps = 50
    sin02 = mpmath.mpf("0.19866933079506121545941262711838975037020672954020")
    f = lambdify(x, sin(x), "mpmath")
    prec = 1e-49  # mpmath precision is around 50 decimal places
    assert -prec < f(mpmath.mpf("0.2")) - sin02 < prec
    raises(TypeError, lambda: f(x))
开发者ID:Soroche,项目名称:sympy,代码行数:7,代码来源:test_lambdify.py

示例2: _optimize_single

def _optimize_single(opt_params):
    '''mapped function for optimization of a single function in a single domain
    
    opt_params is a tuple (expression, subs, bound, use_basinhopping, use_corners)
    returns the interval
    '''

    (e, subs, bound, use_basinhopping, use_corners) = opt_params
    assert not (use_basinhopping and use_corners)

    rv = None
    e = _simplify_eq(e)

    if bound is None:
        rv = _eval_eq_direct(e, subs)
    else:
        under_approx = None

        if use_corners:
            under_approx = _eval_at_corners(e, subs)
        elif use_basinhopping:
            under_approx = _basinhopping(e, subs)
        else:
            under_approx = _eval_at_middle(e, subs)

        # under_approx param should be an array of size 1, since it gets updated
        rv = _eval_eq_bounded(e, subs, bound, [under_approx])

    # convert rv from interval to tuple (for pickling)
    return [float(mpf(rv.a)), float(mpf(rv.b))]
开发者ID:verivital,项目名称:hyst,代码行数:30,代码来源:interval_optimize.py

示例3: daubechis

def daubechis(N):
	# make polynomial
	q_y = [sm.binomial(N-1+k,k) for k in reversed(range(N))]

	# get polynomial roots y[k]
	y = sm.mp.polyroots(q_y, maxsteps=200, extraprec=64)

	z = []
	for yk in y:
		# subustitute y = -1/4z + 1/2 - 1/4/z to factor f(y) = y - y[k]
		f = [sm.mpf('-1/4'), sm.mpf('1/2') - yk, sm.mpf('-1/4')]

		# get polynomial roots z[k]
		z += sm.mp.polyroots(f)

	# make polynomial using the roots within unit circle
	h0z = sm.sqrt('2')
	for zk in z:
		if sm.fabs(zk) < 1:
			h0z *= sympy.sympify('(z-zk)/(1-zk)').subs('zk',zk)

	# adapt vanising moments
	hz = (sympy.sympify('(1+z)/2')**N*h0z).expand()

	# get scaling coefficients
	return [sympy.re(hz.coeff('z',k)) for k in reversed(range(N*2))]
开发者ID:stein2013,项目名称:daubechies_wavelet_coefficients,代码行数:26,代码来源:test.py

示例4: uniform_nodes

def uniform_nodes(n):
  """Return uniform nodes."""

  r = set()
  for i in range(n):
    r.add(mpmath.mpf('-1.0') + i * mpmath.mpf('2.0')/(n-1))

  return map_to_zero_one(r)
开发者ID:dasmy,项目名称:sdcquad,代码行数:8,代码来源:sdcquad.py

示例5: mp_real

def mp_real(x):
    if type(x) == mpc:
        if x.imag == mpf(0):
            return mpf(x.real)
        else:
            raise ValueError
    else:
        return mpf(x)
开发者ID:renatocoutinho,项目名称:bioift,代码行数:8,代码来源:hs_novo.py

示例6: gauss_lobatto

def gauss_lobatto(n):
  """Return Gauss-Lobatto nodes.

  Gauss-Lobatto nodes are roots of P'_{n-1}(x) and -1, 1.
  """

  x = sympy.var('x')
  p = legendre_poly(n-1).diff(x)
  r = find_roots(p)
  r = [mpmath.mpf('-1.0'), mpmath.mpf('1.0')] + r
  return sorted(r)
开发者ID:memmett,项目名称:PyWENO,代码行数:11,代码来源:points.py

示例7: test_mod

def test_mod():
    assert mpf(234) % 1 == 0
    assert mpf(-3) % 256 == 253
    assert mpf(0.25) % 23490.5 == 0.25
    assert mpf(0.25) % -23490.5 == -23490.25
    assert mpf(-0.25) % 23490.5 == 23490.25
    assert mpf(-0.25) % -23490.5 == -0.25
    # Check that these cases are handled efficiently
    assert mpf('1e10000000000') % 1 == 0
    assert mpf('1.23e-1000000000') % 1 == mpf('1.23e-1000000000')
    # test __rmod__
    assert 3 % mpf('1.75') == 1.25
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:12,代码来源:test_division.py

示例8: gauss_lobatto_nodes

def gauss_lobatto_nodes(n):
  """Return Gauss-Lobatto nodes.

  Before mapping to [0,1], the nodes are: roots of :math:`P'_{n-1}(x)`
  and -1, 1.
  """

  x = sympy.var('x')
  p = legendre_poly(n-1).diff(x)
  r = find_roots(p)
  r = [mpmath.mpf('-1.0'), mpmath.mpf('1.0')] + r

  return map_to_zero_one(r)
开发者ID:dasmy,项目名称:sdcquad,代码行数:13,代码来源:sdcquad.py

示例9: as_mpmath

def as_mpmath(x, prec, options):
    x = sympify(x)
    if isinstance(x, C.Zero):
        return mpf(0)
    if isinstance(x, C.Infinity):
        return mpf("inf")
    if isinstance(x, C.NegativeInfinity):
        return mpf("-inf")
    # XXX
    re, im, _, _ = evalf(x, prec, options)
    if im:
        return mpc(re or fzero, im)
    return mpf(re)
开发者ID:smichr,项目名称:sympy,代码行数:13,代码来源:evalf.py

示例10: mc_compute_stationary

def mc_compute_stationary(P, precision=None, tol=None):
    n = P.shape[0]

    if precision is None:
        # Compute eigenvalues and eigenvectors
        eigvals, eigvecs = la.eig(P, left=True, right=False)

        # Find the index for unit eigenvalues
        index = np.where(abs(eigvals - 1.) < 1e-12)[0]

        # Pull out the eigenvectors that correspond to unit eig-vals
        uniteigvecs = eigvecs[:, index]

        stationary_dists = uniteigvecs/np.sum(uniteigvecs, axis=0)

    else:
        # Create a list to store eigvals
        stationary_dists_list = []
        if tol is None:
            # If tolerance isn't specified then use 2*precision
            tol = mp.mpf(2 * 10**(-precision + 1))

        with mp.workdps(precision):
            eigvals, eigvecs = mp.eig(mp.matrix(P), left=True, right=False)

            for ind, el in enumerate(eigvals):
                if el>=(mp.mpf(1)-mp.mpf(tol)) and el<=(mp.mpf(1)+mp.mpf(tol)):
                    stationary_dists_list.append(eigvecs[ind, :])

            stationary_dists = np.asarray(stationary_dists_list).T
            stationary_dists = (stationary_dists/sum(stationary_dists)).astype(np.float)


    # Check to make sure all of the elements of invar_dist are positive
    if np.any(stationary_dists < -1e-16):
        warn("Elements of your invariant distribution were negative; " +
              "Re-trying with additional precision")

        if precision is None:
            stationary_dists = mc_compute_stationary(P, precision=18, tol=tol)

        elif precision is not None:
            raise ValueError("Elements of your stationary distribution were" +
                             "negative.  Try computing with higher precision")

    # Since we will be accessing the columns of this matrix, we
    # might consider adding .astype(np.float, order='F') to make it
    # column major at beginning
    return stationary_dists.squeeze()
开发者ID:CY-Chan,项目名称:quant-econ,代码行数:49,代码来源:mc_tools.py

示例11: test_mpmath_lambda

def test_mpmath_lambda():
    dps = mpmath.mp.dps
    mpmath.mp.dps = 50
    try:
        sin02 = mpmath.mpf("0.19866933079506121545941262711838975037020672954020")
        f = lambdify(x, sin(x), "mpmath")
        prec = 1e-49 # mpmath precision is around 50 decimal places
        assert -prec < f(mpmath.mpf("0.2")) - sin02 < prec
        try:
            f(x) # if this succeeds, it can't be a mpmath function
            assert False
        except TypeError:
            pass
    finally:
        mpmath.mp.dps = dps
开发者ID:minrk,项目名称:sympy,代码行数:15,代码来源:test_lambdify.py

示例12: f

 def f(i, j):
     gamDict = self.__genGammaDict(j, gDict)
     gamDict[-1] = mpf('0')
     def g(n):
         return gamDict[n]
     _g = vectorize(g)
     return _g(i)
开发者ID:agamat,项目名称:rfunction,代码行数:7,代码来源:Rfunc_cnct.py

示例13: test_3250

def test_3250():
    from sympy.mpmath import mpf
    assert str(Float(mpf((1,22,2,22)), '')) == '-88.000'
    assert Float('23.e3', '')._prec == 10
    assert Float('23e3', '')._prec == 20
    assert Float('23000', '')._prec == 20
    assert Float('-23000', '')._prec == 20
开发者ID:amar47shah,项目名称:sympy,代码行数:7,代码来源:test_numbers.py

示例14: log

    def log(self):
        """
        Logaritmo de un intervalo: 'self.log()'

        NOTA: Si el intervalo contiene al 0, pero no es estrictamente negativo,
        se calcula el logaritmo de la intersecci\'on  del intervalo con el dominio
        natural del logaritmo, i.e., [0,+inf].
        """
        
        if 0 in self:

            domainNatural = Intervalo( 0, mpf('inf') )
            intervalRestricted = self.intersection( domainNatural )

            txt_warning = "\nWARNING: Interval {} contains 0 or negative numbers.\n".format(self)
            print txt_warning
            
            txt_warning = "Restricting to the intersection "\
                "with the natural domain of log(x), i.e. {}\n".format(intervalRestricted)
            print txt_warning
            
            return Intervalo( mp.log(intervalRestricted.lo), mp.log(intervalRestricted.hi) )

        elif 0 > self.hi:
            txt_error = 'Interval {} < 0\nlog(x) cannot be computed '\
                'for negative numbers.'.format(self)
            raise ValueError( txt_error )

        else:
            return Intervalo( mp.log(self.lo), mp.log(self.hi) )
开发者ID:dpsanders,项目名称:interval_arithmetic,代码行数:30,代码来源:intervalo.py

示例15: __genGammaDict

 def __genGammaDict(self, j, gDict):
     if self.isZeroT:
         return dict((k, self.scaledVolt[j]**k /gDict[k]) for k in self.wijnTerms)
     else:
         fg = fgamma(self.scaledVolt[j])
         return dict((k, fgamma(self.scaledVolt[j] + mpf(str(k))) / \
                             (fg*gDict[k])) for k in self.wijnTerms)
开发者ID:agamat,项目名称:rfunction,代码行数:7,代码来源:Rfunc_cnct.py


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