def tay(e):
     total = 0
     for j in range(n):
         mat = np.linalg.matrix_power(
             np.matrix(ac.derivative(x[0], x[-1], n)), j) @ f
         total = total + (mat[i] * ((x[e] - x[i])**j) / np.factorial(j))
     return total
Exemplo n.º 2
0
 def __init__(self, n, xshift=0, yshift=0):
     self.n = n
     self.xshift = xshift
     self.yshift = yshift
     self.E = n + 0.5
     self.coef = 1 / np.sqrt(2**n * np.factorial(n)) * (1 / np.pi)**(1/4)
     self.hermite = hermite(n)
Exemplo n.º 3
0
def factorialNumber(numbers):
    result = list()
    for num in numbers:
        result.append(np.factorial(int(num)))

    if len(result) == 1:
        return result[0]
    else:
        return result
Exemplo n.º 4
0
 def annihilation_coefficients( self, x, stencil, max_order ):
        num_dims = x.shape[0]
        num_terms = int( numpy.round( scipy.misc.comb( max_order + num_dims, 
                                                      num_dims ) ) )
        num_stencil_pts = stencil.shape[0]
        print num_terms, num_stencil_pts
        I = multi_indices( num_dims, max_order )
        print I
        phi = numpy.empty( ( num_stencil_pts, num_terms ), numpy.float )
        dy_dx = numpy.empty( ( num_stencil_pts, 1 ), numpy.float )
        for i in range( num_terms + 1 ):
            print stencil**( I[i] )
            phi[:,i] = stencil**( I[i] )
            if ( I[i] == order ):
                dy_dx[i] = numpy.factorial( max_order )
            else:
                dy_dx[i] = 0.0

        return numpy.linalg.solve( phi, dy_dx )
Exemplo n.º 5
0
 def Poisson_pmf(x, lambda1):
     Poiss_pmf = (lambda1**x) * np.exp(-lambda1) / np.factorial(x)
     return Poiss_pmf
Exemplo n.º 6
0
 def ejecutar_mat1(self, funcion):
     if isinstance(funcion, mathfunctions):
         if funcion.funcion == 'abs':
             try:
                 return abs(self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 print('error al convertir valores ')
                 return 0
         if funcion.funcion == 'cbrt':
             try:
                 return self.aritexc.ejecutar_operacion(funcion.op1)**(1. /
                                                                       3.)
             except:
                 print('error al convertir valores ')
                 return 0
         if funcion.funcion == 'ceil':
             try:
                 return np.ceil(self.aritexc.ejecutar_operacion(
                     funcion.op1))
             except:
                 print('error al convertir valores ')
                 return 0
         if funcion.funcion == 'celing':
             try:
                 return np.ceil(self.aritexc.ejecutar_operacion(
                     funcion.op1))
             except:
                 print('error al convertir valores ')
                 return 0
         if funcion.funcion == 'degrees':
             try:
                 return np.degrees(
                     self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 print('error al convertir valores ')
                 return 0
         if funcion.funcion == 'exp':
             try:
                 return np.exp(self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 print('error al convertir valores ')
                 return 0
         if funcion.funcion == 'factorial':
             try:
                 return np.factorial(
                     self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 errorsem.append('error al convertir valores ')
                 return 0
         if funcion.funcion == 'floor':
             try:
                 return np.floor(
                     self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 errorsem.append('error al convertir valores ')
                 return 0
         if funcion.funcion == 'ln':
             try:
                 return np.ln(self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 errorsem.append('error al convertir valores ')
                 return 0
         if funcion.funcion == 'log':
             try:
                 return np.log10(
                     self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 errorsem.append('error al convertir valores ')
                 return 0
         if funcion.funcion == 'radians':
             try:
                 return np.radians(
                     self.aritexc.ejecutar_operacion(funcion.op1))
             except:
                 errorsem.append('error al convertir valores ')
                 return 0
         if funcion.funcion == 'sign':
             try:
                 valor = self.aritexc.ejecutar_operacion(funcion.op1)
                 return -1 if (valor < 0) else 1
             except:
                 errorsem.append('error al convertir valores ')
                 return 0
Exemplo n.º 7
0
import numpy as np
import matplotlib.pyplot as plt

x = -3
N = 20
S = 0

for n in range(0, N + 1):
    S = S + x**n / np.factorial(n)
plt.plot(n, S)
Exemplo n.º 8
0
 def BPOcoef(self,order):
     K = np.ones([order+1],int)
     for ii in range(1,order):
         K[ii] = np.factorial(order)/(np.factorial(ii)*np.factorial(order-ii))
     return K
Exemplo n.º 9
0
def Wigner3j(j1, j2, j3, m1, m2, m3):
    #======================================================================
    # Wigner3j.m by David Terr, Raytheon, 6-17-04
    #
    # Compute the Wigner 3j symbol using the Racah formula [1].
    #
    # Usage:
    # from wigner import Wigner3j
    # wigner = Wigner3j(j1,j2,j3,m1,m2,m3)
    #
    #  / j1 j2 j3 \
    #  |          |
    #  \ m1 m2 m3 /
    #
    # Reference: Wigner 3j-Symbol entry of Eric Weinstein's Mathworld:
    # http://mathworld.wolfram.com/Wigner3j-Symbol.html
    #======================================================================

    # Error checking
    if  2*j1 != np.floor(2*j1) or 2*j2 != np.floor(2*j2) or \
        2*j3 != np.floor(2*j3) or 2*m1 != np.floor(2*m1) or \
        2*m2 != np.floor(2*m2) or 2*m3 != np.floor(2*m3):
        print('All arguments must be integers or half-integers.')
        return -1

    # Additional check if the sum of the second row equals zero
    if m1 + m2 + m3 != 0:
        print('3j-Symbol unphysical')
        return 0

    if j1 - m1 != np.floor(j1 - m1):
        print('2*j1 and 2*m1 must have the same parity')
        return 0

    if j2 - m2 != np.floor(j2 - m2):
        print('2*j2 and 2*m2 must have the same parity')
        return
        0

    if j3 - m3 != np.floor(j3 - m3):
        print('2*j3 and 2*m3 must have the same parity')
        return 0

    if j3 > j1 + j2 or j3 < np.abs(j1 - j2):
        print('j3 is out of bounds')
        return 0

    if np.abs(m1) > j1:
        print('m1 is out of bounds')
        return 0

    if np.abs(m2) > j2:
        print('m2 is out of bounds')
        return 0

    if np.abs(m3) > j3:
        print('m3 is out of bounds')
        return 0

    t1 = j2 - m1 - j3
    t2 = j1 + m2 - j3
    t3 = j1 + j2 - j3
    t4 = j1 - m1
    t5 = j2 + m2

    tmin = max(0, max(t1, t2))
    tmax = min(t3, min(t4, t5))
    tvec = np.arange(tmin, tmax + 1, 1)

    wigner = 0

    for t in tvec:
        wigner += (-1)**t / (np.factorial(t) * np.factorial(t - t1) *
                             np.factorial(t - t2) * np.factorial(t3 - t) *
                             np.factorial(t4 - t) * np.factorial(t5 - t))

    return wigner * (-1)**(j1 - j2 - m3) * np.sqrt(
        np.factorial(j1 + j2 - j3) * np.factorial(j1 - j2 + j3) *
        np.factorial(-j1 + j2 + j3) / np.factorial(j1 + j2 + j3 + 1) *
        np.factorial(j1 + m1) * np.factorial(j1 - m1) * np.factorial(j2 + m2) *
        np.factorial(j2 - m2) * np.factorial(j3 + m3) * np.factorial(j3 - m3))
Exemplo n.º 10
0
def hornersrule(A, t, k):
    I = np.identity(len(A))  # Create I
    p = np.identity(len(A))
    for i in range(k, -1, -1)[:-1]:
        p = np.matmul(np.add(I, t * (1 / np.factorial(k))), p)
    return p
Exemplo n.º 11
0
def find_factorial_sum(n):
    digits = str(n).split()
    return sum([np.factorial(int(d)) for d in digits])
Exemplo n.º 12
0
def find_factorial_sum(n):
    digits = str(n).split()
    return sum([np.factorial(int(d)) for d in digits])