def chebfun(f=None, domain=None, n=None): """Chebfun constructor """ # chebfun() if f is None: return Chebfun.initempty() domain = DefaultPrefs.domain if domain is None else domain # chebfun(lambda x: f(x), ... ) if hasattr(f, "__call__"): return _initfun(f, domain, n) # chebfun('x', ... ) if isinstance(f, str) and len(f) is 1 and f.isalpha(): if n: return _initfun(lambda x: x, domain, n) else: return Chebfun.initidentity(domain) try: # chebfun(3.14, ... ), chebfun('3.14', ... ) return Chebfun.initconst(float(f), domain) except: raise ValueError(f)
def chebfun(f=None, domain=None, n=None): """Chebfun constructor """ # chebfun() if f is None: return Chebfun.initempty() domain = DefaultPrefs.domain if domain is None else domain # chebfun(lambda x: f(x), ... ) if hasattr(f, "__call__"): return Chebfun.initfun(f, domain, n) # chebfun('x', ... ) if isinstance(f, str) and len(f) is 1 and f.isalpha(): if n: return Chebfun.initfun(lambda x: x, domain, n) else: return Chebfun.initidentity(domain) try: # chebfun(3.14, ... ), chebfun('3.14', ... ) return Chebfun.initconst(float(f), domain) except: raise ValueError(f)
def test_initidentity(self): _doms = ( np.linspace(-1,1,2), np.linspace(-1,1,11), np.linspace(-10,17,351), np.linspace(-9.3,-3.2,22), np.linspace(2.5,144.3,2112), ) for _dom in _doms: ff = Chebfun.initidentity(_dom) a, b = ff.support xx = np.linspace(a, b, 1001) tol = eps * ff.hscale self.assertLessEqual(infnorm(ff(xx)-xx), tol) # test the default case ff = Chebfun.initidentity() a, b = ff.support xx = np.linspace(a, b, 1001) tol = eps * ff.hscale self.assertLessEqual(infnorm(ff(xx)-xx), tol)
def test_initidentity(self): _doms = ( np.linspace(-1, 1, 2), np.linspace(-1, 1, 11), np.linspace(-10, 17, 351), np.linspace(-9.3, -3.2, 22), np.linspace(2.5, 144.3, 2112), ) for _dom in _doms: ff = Chebfun.initidentity(_dom) a, b = ff.support xx = np.linspace(a, b, 1001) tol = eps * ff.hscale self.assertLessEqual(infnorm(ff(xx) - xx), tol) # test the default case ff = Chebfun.initidentity() a, b = ff.support xx = np.linspace(a, b, 1001) tol = eps * ff.hscale self.assertLessEqual(infnorm(ff(xx) - xx), tol)