def chunk(self, f, a=-1, b=1, n=31, tol=1e-15): x = self.chebNodes(a, b, n) fx = f(x) cfxl = self.chebTransform(fx) x = np.linspace(a, b, 10000) fxl = self.chebEval(cfxl, x, a, b) # print(cfxl) # plt.loglog(np.abs(cfxl)) # plt.show() x = self.chebNodes(a, b, n) fx = f(g(x)) # nn = np.arange(fx.size) cfxh = self.chebTransform(fx) x = np.linspace(a, b, 10000) fxh = self.chebEval(cfxh, x, a, b) # plt.plot(x, fxh) # plt.plot(x, fxl) # plt.show() print(int) cf = np_cheb.chebsub(cfxh, cfxl) # cdf = self.chebDiff(cfxh, 3) x = np.linspace(a, b, 10000) df = self.chebEval(cf, x, a, b) # plt.loglog(np.abs(cf)) # plt.show() plt.plot(x, df) plt.show() roots = self.chebRoots(cdf, a, b) sf = self.chebEval(cf, roots, a, b) dp = roots[np.argmax(np.abs(sf))] # print('root', dp, 'value', np.max(np.abs(fxh - fxl))) # plt.plot(x, fxh - fxl) # plt.show() return dp, np.max(np.abs(sf))
def test_chebsub(self) : for i in range(5) : for j in range(5) : msg = "At i=%d, j=%d" % (i,j) tgt = np.zeros(max(i,j) + 1) tgt[i] += 1 tgt[j] -= 1 res = cheb.chebsub([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_chebsub(self): for i in range(5): for j in range(5): msg = "At i=%d, j=%d" % (i, j) tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 res = cheb.chebsub([0]*i + [1], [0]*j + [1]) assert_equal(trim(res), trim(tgt), err_msg=msg)
def chebsub(c1, c2): from numpy.polynomial.chebyshev import chebsub return chebsub(c1, c2)