Ejemplo n.º 1
0
def besselJ(n, x, order):
    """
	Bessel functions.
	"""
    from pyranha.math import factorial
    from fractions import Fraction as F
    temp = 0
    for m in range(0, int((order - n) / 2) + 1):
        temp = temp + F((-1)**m,
                        factorial(m) * factorial(m + n)) * (x / 2)**(2 * m + n)
    return temp
Ejemplo n.º 2
0
def legendrePn(n, x):
    """
	Legendre polynomials.
	"""
    from pyranha.math import factorial
    from fractions import Fraction as F
    temp = 0
    for k in range(0, int(n / 2) + 1):
        temp = temp + (-1)**k * F(
            factorial(2 * (n - k)), 2**n * factorial(k) * factorial(n - k) *
            factorial(n - 2 * k)) * x**(n - 2 * k)
    return temp
Ejemplo n.º 3
0
Archivo: ham.py Proyecto: celesmec/eps
def one_delta(p, q, n, c_max, deg, isAver, isCalc, isPrint):
    """
	Construction of the expansion 1/DELTA through cosines between radius vectors.
	- n is maximum degree of variables;
	- c_max is maximum power of cosines;
	- deg is degree of 1/DELTA.
	"""
    from pyranha.math import factorial
    start = time.time()
    ra = rrr(p, n, 1)
    br = one_r(q, n, 1)
    if isAver and deg == 1:
        for item in br.list:
            if item[1] == epst(1):
                delta = item[0] * item[1]
    else:
        delta = br
    cos_deg = [1]
    for i in range(1, c_max + 1):
        if isCalc:
            cos_deg.append(cosine(p, q, n, i))
        else:
            cos_temp = epst()
            lf(
                cos_temp, PREFIX + 'COS/' + str(n) + '/' + str(i) +
                '/cosine_' + str(q) + str(p) + '.epst.boostp.bz2',
                df.boost_portable, cf.bzip2)
            cos_deg.append(cos_temp)
        if isPrint:
            if isCalc:
                print 'cosine with power of', i, 'is calculated for %.2f' % (
                    time.time() - start), 's'
            else:
                print 'cosine with power of', i, 'is read for %.2f' % (
                    time.time() - start), 's'
    ##################################################
    pt.set_auto_truncate_degree(F(n), [
        'x' + str(p), 'y' + str(p), 'u' + str(p), 'v' + str(p), 'x' + str(q),
        'y' + str(q), 'u' + str(q), 'v' + str(q)
    ])
    rr = ra * br
    for c in range(1, c_max + 1):
        legPn = 0
        for k in range(0, int(c / 2) + 1):
            legPn = legPn + (-1)**k * F(
                factorial(2 * (c - k)), 2**c * factorial(k) *
                factorial(c - k) * factorial(c - 2 * k)) * cos_deg[c - 2 * k]
        rr_n = br * rr**c
        if isAver and deg == 1:
            temp = 0
            for item in rr_n.list:
                for jtem in legPn.list:
                    trig = item[1] * jtem[1]
                    for ktem in trig.list:
                        if ktem[1] == 1:
                            temp = temp + item[0] * jtem[0] * ktem[0]
        else:
            temp = rr_n * legPn
        delta = delta + temp
        if isPrint:
            print 'Legendre polynomial with power of', c, 'is added for %.2f' % (
                time.time() - start), 's'
    if deg > 1: delta = delta**deg
    pt.unset_auto_truncate_degree()
    return delta