예제 #1
0
 def test_isconst(self):
     self.assertFalse(self.f0.isconst)
     self.assertFalse(self.f1.isconst)
     self.assertFalse(self.f2.isconst)
     c1 = Chebfun.initfun_fixedlen(lambda x: 0*x+3, 1, [-2,-1,0,1,2,3])
     c2 = Chebfun.initfun_fixedlen(lambda x: 0*x-1, 1, [-2,3])
     self.assertTrue(c1.isconst)
     self.assertTrue(c2.isconst)
예제 #2
0
 def test_isconst(self):
     self.assertFalse(self.f0.isconst)
     self.assertFalse(self.f1.isconst)
     self.assertFalse(self.f2.isconst)
     c1 = Chebfun.initfun_fixedlen(lambda x: 0*x+3, 1, [-2,-1,0,1,2,3])
     c2 = Chebfun.initfun_fixedlen(lambda x: 0*x-1, 1, [-2,3])
     self.assertTrue(c1.isconst)
     self.assertTrue(c2.isconst)
예제 #3
0
 def test_initfun_fixedlen_succeeds(self):
     self.assertTrue(Chebfun.initfun_fixedlen(self.f, [], [-2,-1,0]).isempty)
     # check that providing a vector with None elements calls the
     # Tech adaptive constructor
     g0 = Chebfun.initfun_adaptive(self.f, [-2,-1,0])
     g1 = Chebfun.initfun_fixedlen(self.f, [None,None], [-2,-1,0])
     g2 = Chebfun.initfun_fixedlen(self.f, [None,40], [-2,-1,0])
     for fun1, fun2 in zip(g1,g0):
         self.assertEqual(sum(fun1.coeffs-fun2.coeffs), 0)
     self.assertEqual(sum(g2.funs[0].coeffs-g0.funs[0].coeffs), 0)
예제 #4
0
 def test_initfun_fixedlen_succeeds(self):
     self.assertTrue(Chebfun.initfun_fixedlen(self.f, [], [-2,-1,0]).isempty)
     # check that providing a vector with None elements calls the
     # Tech adaptive constructor
     g0 = Chebfun.initfun_adaptive(self.f, [-2,-1,0])
     g1 = Chebfun.initfun_fixedlen(self.f, [None,None], [-2,-1,0])
     g2 = Chebfun.initfun_fixedlen(self.f, [None,40], [-2,-1,0])
     for fun1, fun2 in zip(g1,g0):
         self.assertEqual(sum(fun1.coeffs-fun2.coeffs), 0)
     self.assertEqual(sum(g2.funs[0].coeffs-g0.funs[0].coeffs), 0)
예제 #5
0
 def test_initfun_fixedlen_succeeds(self):
     # check providing a vector with None elements calls the
     # Tech adaptive constructor
     dom = [-2, -1, 0]
     g0 = Chebfun.initfun_adaptive(self.f, dom)
     g1 = Chebfun.initfun_fixedlen(self.f, [None, None], dom)
     g2 = Chebfun.initfun_fixedlen(self.f, [None, 40], dom)
     g3 = Chebfun.initfun_fixedlen(self.f, None, dom)
     for funA, funB in zip(g1, g0):
         self.assertEqual(sum(funA.coeffs - funB.coeffs), 0)
     for funA, funB in zip(g3, g0):
         self.assertEqual(sum(funA.coeffs - funB.coeffs), 0)
     self.assertEqual(sum(g2.funs[0].coeffs - g0.funs[0].coeffs), 0)
예제 #6
0
 def test_initfun_fixedlen_continuous_domain(self):
     ff = Chebfun.initfun_fixedlen(self.f, 20, [-2,-1])
     self.assertEqual(ff.funs.size, 1)
     a, b = ff.breakdata.keys()
     fa, fb, = ff.breakdata.values()
     self.assertEqual(a,-2)
     self.assertEqual(b,-1)
     self.assertLessEqual(abs(fa-self.f(-2)), eps)
     self.assertLessEqual(abs(fb-self.f(-1)), eps)
예제 #7
0
 def test_initfun_fixedlen_continuous_domain(self):
     ff = Chebfun.initfun_fixedlen(self.f, 20, [-2, -1])
     self.assertEqual(ff.funs.size, 1)
     a, b = ff.breakdata.keys()
     fa, fb, = ff.breakdata.values()
     self.assertEqual(a, -2)
     self.assertEqual(b, -1)
     self.assertLessEqual(abs(fa - self.f(-2)), eps)
     self.assertLessEqual(abs(fb - self.f(-1)), eps)
예제 #8
0
 def test_initfun_fixedlen_piecewise_domain_1(self):
     ff = Chebfun.initfun_fixedlen(self.f, [30,20], [-2,0,1])
     self.assertEqual(ff.funs.size, 2)
     a, b, c = ff.breakdata.keys()
     fa, fb, fc = ff.breakdata.values()
     self.assertEqual(a,-2)
     self.assertEqual(b, 0)
     self.assertEqual(c, 1)
     self.assertLessEqual(abs(fa-self.f(-2)), 3*eps)
     self.assertLessEqual(abs(fb-self.f( 0)), 3*eps)
     self.assertLessEqual(abs(fc-self.f( 1)), 6*eps)
예제 #9
0
 def test_initfun_fixedlen_piecewise_domain_1(self):
     ff = Chebfun.initfun_fixedlen(self.f, [30, 20], [-2, 0, 1])
     self.assertEqual(ff.funs.size, 2)
     a, b, c = ff.breakdata.keys()
     fa, fb, fc = ff.breakdata.values()
     self.assertEqual(a, -2)
     self.assertEqual(b, 0)
     self.assertEqual(c, 1)
     self.assertLessEqual(abs(fa - self.f(-2)), 3 * eps)
     self.assertLessEqual(abs(fb - self.f(0)), 3 * eps)
     self.assertLessEqual(abs(fc - self.f(1)), 6 * eps)
예제 #10
0
 def test_x_property(self):
     _doms = (
         np.linspace(-1,1,2),
         np.linspace(-1,1,11),
         np.linspace(-9.3,-3.2,22),
     )
     for _dom in _doms:
         f = Chebfun.initfun_fixedlen(sin, 1000, _dom)
         x = f.x
         a, b = x.support
         pts = np.linspace(a, b, 1001)
         tol = eps * f.hscale
         self.assertLessEqual(infnorm(x(pts)-pts), tol)
예제 #11
0
 def test_x_property(self):
     _doms = (
         np.linspace(-1, 1, 2),
         np.linspace(-1, 1, 11),
         np.linspace(-9.3, -3.2, 22),
     )
     for _dom in _doms:
         f = Chebfun.initfun_fixedlen(sin, 1000, _dom)
         x = f.x
         a, b = x.support
         pts = np.linspace(a, b, 1001)
         tol = eps * f.hscale
         self.assertLessEqual(infnorm(x(pts) - pts), tol)
예제 #12
0
 def test_restrict_(self):
     # test a variety of domains with breaks
     doms = [(-4,4), (-4,0,4), (-2,-1, 0.3, 1, 2.5)]
     for dom in doms:
         ff = Chebfun.initfun_fixedlen(cos, 25, domain=dom)
         # define some arbitrary subdomains
         yy = np.linspace(dom[0], dom[-1], 11)
         subdoms = [yy, yy[2:7], yy[::2]]
         for subdom in subdoms:
             xx = np.linspace(subdom[0], subdom[-1], 1001)
             gg = ff._restrict(subdom)
             vscl = ff.vscale
             hscl = ff.hscale
             lscl = max([fun.size for fun in ff])
             tol = vscl*hscl*lscl*eps
             # sample the restricted function and comapre with original
             self.assertLessEqual(infnorm(ff(xx)-gg(xx)), tol)
             # check there are at least as many funs as subdom elements
             self.assertGreaterEqual(len(gg.funs), len(subdom)-1)
             for fun in gg:
                 # chec each fun has length 25
                 self.assertEqual(fun.size, 25)
예제 #13
0
 def test_restrict_(self):
     # test a variety of domains with breaks
     doms = [(-4, 4), (-4, 0, 4), (-2, -1, 0.3, 1, 2.5)]
     for dom in doms:
         ff = Chebfun.initfun_fixedlen(cos, 25, domain=dom)
         # define some arbitrary subdomains
         yy = np.linspace(dom[0], dom[-1], 11)
         subdoms = [yy, yy[2:7], yy[::2]]
         for subdom in subdoms:
             xx = np.linspace(subdom[0], subdom[-1], 1001)
             gg = ff._restrict(subdom)
             vscl = ff.vscale
             hscl = ff.hscale
             lscl = max([fun.size for fun in ff])
             tol = vscl * hscl * lscl * eps
             # sample the restricted function and comapre with original
             self.assertLessEqual(infnorm(ff(xx) - gg(xx)), tol)
             # check there are at least as many funs as subdom elements
             self.assertGreaterEqual(len(gg.funs), len(subdom) - 1)
             for fun in gg:
                 # chec each fun has length 25
                 self.assertEqual(fun.size, 25)
예제 #14
0
파일: ui.py 프로젝트: nbren12/chebpy
def _initfun(f, domain, n):
    if n is None:
        return Chebfun.initfun_adaptive(f, domain)
    else:
        return Chebfun.initfun_fixedlen(f, n, domain)
예제 #15
0
 def test_initfun_fixedlen_empty_domain(self):
     f = Chebfun.initfun_fixedlen(self.f, n=10, domain=[])
     self.assertTrue(f.isempty)