def C1(n): """ integral related to first order finite Larmor radius effect """ c1 = poly2cheb([0, 0, 0, 0, -1.5, 0, 2]) c2 = nthpoly(2 * n) kernel = chebmul(c1, c2) cint = chebint(kernel) return chebval(1, cint)
def C0(n): """ integral related to zero'th order finite Larmor radius effect """ c1 = poly2cheb([0, 1, 0, -2]) c2 = nthpoly(2 * n) kernel = chebmul(c1, c2) cint = chebint(kernel) return chebval(1, cint)
def test_chebmul(self) : for i in range(5) : for j in range(5) : msg = "At i=%d, j=%d" % (i,j) tgt = np.zeros(i + j + 1) tgt[i + j] += .5 tgt[abs(i - j)] += .5 res = cheb.chebmul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_chebmul(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(i + j + 1) tgt[i + j] += .5 tgt[abs(i - j)] += .5 res = cheb.chebmul([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_chebdiv(self) : for i in range(5) : for j in range(5) : msg = "At i=%d, j=%d" % (i,j) ci = [0]*i + [1] cj = [0]*j + [1] tgt = cheb.chebadd(ci, cj) quo, rem = cheb.chebdiv(tgt, ci) res = cheb.chebadd(cheb.chebmul(quo, ci), rem) assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_chebdiv(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) ci = [0]*i + [1] cj = [0]*j + [1] tgt = cheb.chebadd(ci, cj) quo, rem = cheb.chebdiv(tgt, ci) res = cheb.chebadd(cheb.chebmul(quo, ci), rem) assert_equal(trim(res), trim(tgt), err_msg=msg)
def gegenbauerReconstruction(self, A, N): # np.set_printoptions(precision=3, suppress=True) entireA = np.hstack((A[1:][::-1], A)) n = np.size(entireA) x = self.chebNodes(n=N) k = np.arange(-A.size + 1, A.size) xx, kk = np.meshgrid(x, k) M = np.exp(1j * kk * np.pi * xx).T fx = M.dot(entireA) cfx = self.chebTransform(fx) # gamma = 1 # print(gamma) l = N # l = 4.5 xx, NN = np.meshgrid(x, np.arange(N)) gx = special.eval_gegenbauer(NN, l, xx) # print(gx) cgx = (self.chebTransform(gx.T)).T # print(cgx) wx = np.power(1 - x * x, l - 0.5) cwx = self.chebTransform(wx) cIx = [] for i in range(gx.shape[0]): cIx.append(np_cheb.chebmul(cwx, cgx[i, :])) # print(cgx[i, :]) cIx = np.asarray(cIx) I = [] h = np.sqrt(np.pi) * special.eval_gegenbauer(np.arange(N), l, 1) * special.gamma(l + 0.5) / special.gamma(l) / ( N + l) for it in cIx: I.append(np.real(self.integrate(it, cfx))) I /= h # print(np.array(I)) # print(gx) plt.plot(x, (gx.T).dot(I)) plt.show()
def chebmul(c1, c2): from numpy.polynomial.chebyshev import chebmul return chebmul(c1, c2)