Beispiel #1
0
    def solve(self, init, x):
        A = np.zeros([2, 2])
        A[0][0] = special.lpmn(self.order, self.degree,
                               self.function(x[0]))[0][self.order][self.degree]
        A[0][1] = special.lqmn(self.order, self.degree,
                               self.function(x[0]))[0][self.order][self.degree]
        A[1][0] = self.function.deriv(1)(x[0]) * special.lpmn(
            self.order, self.degree, self.function(
                x[0]))[1][self.order][self.degree]
        A[1][1] = self.function.deriv(1)(x[0]) * special.lqmn(
            self.order, self.degree, self.function(
                x[0]))[1][self.order][self.degree]
        print(A)
        c = np.linalg.solve(A, init)
        self.c = c
        y = np.zeros((len(x), 2))
        for i in range(len(x)):
            for j in range(2):
                if j == 0:
                    y[i][j] = \
                    c[0]*special.lpmn(self.order, self.degree, self.function(x[i]))[j][self.order][self.degree] + \
                    c[1]*special.lqmn(self.order, self.degree, self.function(x[i]))[j][self.order][self.degree]

                elif j == 1:
                    y[i][j] = \
                    c[0]*self.function.deriv(1)(x[i])*special.lpmn(self.order, self.degree, self.function(x[i]))[j][self.order][self.degree] + \
                    c[1]*self.function.deriv(1)(x[i])*special.lqmn(self.order, self.degree, self.function(x[i]))[j][self.order][self.degree]
        self.x = x
        self.y = y
        return y
def cmp_LPQL(Nx,xmin,xmax, maxm,maxl, ist, Sol, Ck, Modd):
	
	Xx=1-xmin+logspace(log10(xmin),log10(xmax),Nx)
	# For rombohedral method we need the change of variable to equidistant mesh
	# We can change the variable Int[f(x),{x,1,Inf}] = Int[ exp(t) f(1-xmin+exp(t)), {t, log(xmin),inf}]
	# Here t is distributed in linear mesh with spacing dxi, and exp(t)=x-1+xmin, because we
	# constructued logarithmic mesh by x=1-xmin+exp(t)
	Expu = Xx-1.+xmin 
	dxi = (log(Expu[-1])-log(Expu[0]))/(len(Expu)-1.)
	
	Qlm_all = array([special.lqmn(maxm,maxl,x)[0] for x in Xx])
	Plm_all = array([special.lpmn(maxm,maxl,x)[0] for x in Xx])
	Qlm_all[0]=0.0  # This diverges, hence we set it to zero
	
	LPL = zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	LQL = zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	LPxL= zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	LQxL= zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	LLP = zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	LLQ = zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	LLPx= zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	LLQx= zeros((len(ist),maxl+1,len(Xx)),dtype=float)
	
	for i,(i1,i2) in enumerate(ist):
		(R1,Ene1,m1,p1,A1) = Sol[i1]
		(R2,Ene2,m2,p2,A2) = Sol[i2]
		print 'i1=', i1, 'i2=', i2, 'm1=', m1, 'm2=', m2
		
		m = abs(m1-m2)
		
		Qlm = transpose(Qlm_all[:,m])
		Plm = transpose(Plm_all[:,m])
		LL   = array([Lambda(x,m1,p1,Ck[i1]) * Lambda(x,m2,p2,Ck[i2]) for ix,x in enumerate(Xx)])
		
		for il in range(m,maxl+1):
			odd = (Modd[i1]+Modd[i2]+il+m)%2
			
			if odd: continue
			

			LLQ [i,il,:] = LL * Qlm[il,:]
			LLQx[i,il,:] = LLQ[i,il,:] * Xx**2
			LLP [i,il,:] = LL * Plm[il,:]
			LLPx[i,il,:] = LLP[i,il,:] * Xx**2


			for ix in range(len(Xx)):
				LPL [i,il,ix] = simps(LLP [i,il,:ix+1],Xx[:ix+1])
				LPxL[i,il,ix] = simps(LLPx[i,il,:ix+1],Xx[:ix+1])
				LQL [i,il,ix] = simps(LLQ [i,il,ix:],Xx[ix:])
				LQxL[i,il,ix] = simps(LLQx[i,il,ix:],Xx[ix:])
	    
	
	return (LPL, LQL, LPxL, LQxL, LLP, LLQ, LLPx, LLQx)
Beispiel #3
0
def legendre_q_via_lqmn(n, x):
    return lqmn(0, n, x)[0][0,-1]
Beispiel #4
0
def legendre_q_via_lqmn(n, x):
    return lqmn(0, n, x)[0][0,-1]
Beispiel #5
0
 def lqnm(n, m, z):
     return sc.lqmn(int(m.real), int(n.real), z)[0][-1,-1]
Beispiel #6
0
 def lqnm(n, m, z):
     return sc.lqmn(m, n, z)[0][-1,-1]
Beispiel #7
0
def fin_potential(domain, x):
    """Compute the potential matrix for a finite domain.

    Arguments:
        domain  (FinDomain) target domain
    Returns:
        matrix  (np.array(fns, fns))    calculated potential matrix
    """

    # Rename some useful quantities
    max_m = domain.functions
    d = x - (min(domain.position) + domain.halfwidth)

    # Setup storage for the output
    matrix = zeros((max_m, max_m), dtype=double)
    iterator = np.nditer(matrix, flags=["multi_index"], op_flags=["readwrite"])

    if abs(1 - abs(d) / domain.halfwidth) < 1e-14:
        while not iterator.finished:
            m, n = iterator.multi_index
            mu = max(m, n) + 1
            nu = min(m, n) + 1

            integral = (sqrt((mu + 1.5) * (nu + 1.5)) / (2 * domain.halfwidth)) * sqrt(
                (nu * (nu + 1) * (nu + 2) * (nu + 3))
                / (mu * (mu + 1) * (mu + 2) * (mu + 3))
            )

            if d < 0:
                iterator[0] = (-1) ** (m + n) * integral
            else:
                iterator[0] = integral

            iterator.iternext()

    else:
        while not iterator.finished:
            m, n = iterator.multi_index
            m += 1
            n += 1

            normalisation = (
                2.0
                * sqrt(
                    np.float64((m + 1.5) * (n + 1.5))
                    / np.float64(
                        m
                        * (m + 1)
                        * (m + 2)
                        * (m + 3)
                        * n
                        * (n + 1)
                        * (n + 2)
                        * (n + 3)
                    )
                )
                / domain.halfwidth
            )

            if d > 1:
                legendre = (
                    lpmn(2, min(m, n) + 1, d / domain.halfwidth)[0][2][-1]
                    * lqmn(2, max(m, n) + 1, d / domain.halfwidth)[0][2][-1]
                )
            else:
                legendre = (
                    lpmn(2, min(m, n) + 1, d / domain.halfwidth)[0][2][-1]
                    * (-1) ** max(m, n)
                    * lqmn(2, max(m, n) + 1, abs(d / domain.halfwidth))[0][2][-1]
                )

            if d < 0:
                iterator[0] = -normalisation * legendre
            else:
                iterator[0] = normalisation * legendre

            iterator.iternext()
    return matrix
Beispiel #8
0
 def lqnm(n, m, z):
     return sc.lqmn(int(m.real), int(n.real), z)[0][-1, -1]
Beispiel #9
0
 def lqnm(n, m, z):
     return sc.lqmn(m, n, z)[0][-1, -1]