def setUp(self): self.f1 = Chebfun.initfun_adaptive(lambda x: cos(4 * pi * x), np.linspace(-10, 10, 101)) self.f2 = Chebfun.initfun_adaptive(lambda x: sin(2 * pi * x), np.linspace(-1, 1, 5)) self.f3 = Chebfun.initfun_adaptive(lambda x: sin(4 * pi * x), np.linspace(-10, 10, 101))
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 setUp(self): self.f1 = Chebfun.initfun_adaptive(lambda x: cos(4*pi*x), np.linspace(-10,10,101)) self.f2 = Chebfun.initfun_adaptive(lambda x: sin(2*pi*x), np.linspace(-1,1,5)) self.f3 = Chebfun.initfun_adaptive(lambda x: sin(4*pi*x), np.linspace(-10,10,101))
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_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)
def setUp(self): f = lambda x: sin(4*x-1.4) self.df = lambda x: 4*cos(4*x-1.4) self.If = lambda x: -.25*cos(4*x-1.4) self.f1 = Chebfun.initfun_adaptive(f, [-1,1]) self.f2 = Chebfun.initfun_adaptive(f, [-3,0,1]) self.f3 = Chebfun.initfun_adaptive(f, [-2,-0.3,1.2]) self.f4 = Chebfun.initfun_adaptive(f, linspace(-1,1,11))
def test_initconst(self): self.assertTrue(Chebfun.initconst(1, [-1,1]).isconst) self.assertTrue(Chebfun.initconst(-10, np.linspace(-1,1,11)).isconst) self.assertTrue(Chebfun.initconst(3, [-2,0,1]).isconst) self.assertTrue(Chebfun.initconst(3.14, np.linspace(-100,-90,11)).isconst) self.assertFalse(Chebfun([self.fun0]).isconst) self.assertFalse(Chebfun([self.fun1]).isconst) self.assertFalse(Chebfun([self.fun2]).isconst) self.assertFalse(Chebfun([self.fun0, self.fun1]).isconst)
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)
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)
def test__call__general_evaluation(self): f = lambda x: sin(4*x) + exp(cos(14*x)) - 1.4 npts = 50000 dom1 = [-1,1] dom2 = [-1,0,1] dom3 = [-2,-0.3,1.2] ff1 = Chebfun.initfun_adaptive(f, dom1) ff2 = Chebfun.initfun_adaptive(f, dom2) ff3 = Chebfun.initfun_adaptive(f, dom3) x1 = np.linspace(dom1[0], dom1[-1], npts) x2 = np.linspace(dom2[0], dom2[-1], npts) x3 = np.linspace(dom3[0], dom3[-1], npts) self.assertLessEqual(infnorm(f(x1)-ff1(x1)), 5e1*eps) self.assertLessEqual(infnorm(f(x2)-ff2(x2)), 2e1*eps) self.assertLessEqual(infnorm(f(x3)-ff3(x3)), 5e1*eps)
def test__call__general_evaluation(self): f = lambda x: sin(4 * x) + exp(cos(14 * x)) - 1.4 npts = 50000 dom1 = [-1, 1] dom2 = [-1, 0, 1] dom3 = [-2, -0.3, 1.2] ff1 = Chebfun.initfun_adaptive(f, dom1) ff2 = Chebfun.initfun_adaptive(f, dom2) ff3 = Chebfun.initfun_adaptive(f, dom3) x1 = np.linspace(dom1[0], dom1[-1], npts) x2 = np.linspace(dom2[0], dom2[-1], npts) x3 = np.linspace(dom3[0], dom3[-1], npts) self.assertLessEqual(infnorm(f(x1) - ff1(x1)), 5e1 * eps) self.assertLessEqual(infnorm(f(x2) - ff2(x2)), 2e1 * eps) self.assertLessEqual(infnorm(f(x3) - ff3(x3)), 5e1 * eps)
def test_truediv_empty(self): for (f, _, _) in testfunctions: for dom, _ in chebfun_testdomains: a, b = dom ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 13)) self.assertTrue((self.emptyfun / ff).isempty) self.assertTrue((ff / self.emptyfun).isempty)
def test_truediv_empty(self): for (f, _, _) in testfunctions: for dom, _ in chebfun_testdomains: a, b = dom ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 13)) self.assertTrue((self.emptyfun/ff).isempty) self.assertTrue((ff/self.emptyfun).isempty)
def piecewise_constant(domain=[-1, 0, 1], values=[0, 1]): """Initlialise a piecewise constant Chebfun""" funs = [] intervals = [x for x in Domain(domain).intervals] for interval, value in zip(intervals, values): funs.append(Bndfun.initconst(value, interval)) return Chebfun(funs)
def test__mul__rmul__empty(self): for (f, _, _) in testfunctions: for dom, _ in chebfun_testdomains: a, b = dom ff = Chebfun.initfun_adaptive(f, linspace(a, b, 13)) self.assertTrue((self.emptyfun*ff).isempty) self.assertTrue((ff*self.emptyfun).isempty)
def test_initconst(self): self.assertTrue(Chebfun.initconst(1, [-1,1]).isconst) self.assertTrue(Chebfun.initconst(-10, linspace(-1,1,11)).isconst) self.assertTrue(Chebfun.initconst(3, [-2,0,1]).isconst) self.assertTrue(Chebfun.initconst(3.14, linspace(-100,-90,11)).isconst) self.assertFalse(Chebfun([self.fun0]).isconst) self.assertFalse(Chebfun([self.fun1]).isconst) self.assertFalse(Chebfun([self.fun2]).isconst) self.assertFalse(Chebfun([self.fun0, self.fun1]).isconst)
def binaryOpTester(f, g, binop, dom, tol): a, b = dom xx = linspace(a,b,1001) n, m = 3, 8 ff = Chebfun.initfun_adaptive(f, linspace(a,b,n+1)) gg = Chebfun.initfun_adaptive(g, linspace(a,b,m+1)) FG = lambda x: binop(f(x), g(x)) fg = binop(ff, gg) def tester(self): vscl = max([ff.vscale, gg.vscale]) hscl = max([ff.hscale, gg.hscale]) lscl = max([fun.size for fun in append(ff.funs, gg.funs)]) self.assertEqual(ff.funs.size, n) self.assertEqual(gg.funs.size, m) self.assertEqual(fg.funs.size, n+m-1) self.assertLessEqual(infnorm(fg(xx)-FG(xx)), vscl*hscl*lscl*tol) return tester
def binaryOpTester(f, g, binop, dom, tol): a, b = dom xx = np.linspace(a,b,1001) n, m = 3, 8 ff = Chebfun.initfun_adaptive(f, np.linspace(a,b,n+1)) gg = Chebfun.initfun_adaptive(g, np.linspace(a,b,m+1)) FG = lambda x: binop(f(x), g(x)) fg = binop(ff, gg) def tester(self): vscl = max([ff.vscale, gg.vscale]) hscl = max([ff.hscale, gg.hscale]) lscl = max([fun.size for fun in np.append(ff.funs, gg.funs)]) self.assertEqual(ff.funs.size, n) self.assertEqual(gg.funs.size, m) self.assertEqual(fg.funs.size, n+m-1) self.assertLessEqual(infnorm(fg(xx)-FG(xx)), vscl*hscl*lscl*tol) return tester
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)
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)
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_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)
def ufuncTester(ufunc, f, interval, tol): a,b = interval ff = Chebfun.initfun_adaptive(f, linspace(a,b,13)) gg = lambda x: ufunc(f(x)) GG = ufunc(ff) def tester(self): xx = interval(self.yy) vscl = GG.vscale lscl = sum([fun.size for fun in GG]) self.assertLessEqual(infnorm(gg(xx)-GG(xx)), vscl*lscl*tol) return tester
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)
def test_initfun_adaptive_piecewise_domain(self): ff = Chebfun.initfun_adaptive(self.f, [-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)), eps) self.assertLessEqual(abs(fb - self.f(0)), eps) self.assertLessEqual(abs(fc - self.f(1)), 2 * eps)
def test_initfun_adaptive_piecewise_domain(self): ff = Chebfun.initfun_adaptive(self.f, [-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)), eps) self.assertLessEqual(abs(fb-self.f( 0)), eps) self.assertLessEqual(abs(fc-self.f( 1)), 2*eps)
def setUp(self): f = lambda x: sin(4*x-1.4) g = lambda x: exp(x) self.df = lambda x: 4*cos(4*x-1.4) self.If = lambda x: -.25*cos(4*x-1.4) self.f1 = Chebfun.initfun_adaptive(f, [-1,1]) self.f2 = Chebfun.initfun_adaptive(f, [-3,0,1]) self.f3 = Chebfun.initfun_adaptive(f, [-2,-0.3,1.2]) self.f4 = Chebfun.initfun_adaptive(f, np.linspace(-1,1,11)) self.g1 = Chebfun.initfun_adaptive(g, [-1,1]) self.g2 = Chebfun.initfun_adaptive(g, [-3,0,1]) self.g3 = Chebfun.initfun_adaptive(g, [-2,-0.3,1.2]) self.g4 = Chebfun.initfun_adaptive(g, np.linspace(-1,1,11))
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 ufuncTester(ufunc, f, interval, tol): a,b = interval ff = Chebfun.initfun_adaptive(f, np.linspace(a,b,13)) gg = lambda x: ufunc(f(x)) GG = getattr(ff, ufunc.__name__)() def tester(self): xx = interval(self.yy) vscl = GG.vscale lscl = sum([fun.size for fun in GG]) self.assertLessEqual(infnorm(gg(xx)-GG(xx)), vscl*lscl*tol) return tester
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)
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)
def unaryOpTester(f, unaryop, dom, tol): a, b = dom xx = np.linspace(a,b,1001) ff = Chebfun.initfun_adaptive(f, np.linspace(a,b,9)) GG = lambda x: unaryop(f(x)) gg = unaryop(ff) def tester(self): vscl = ff.vscale hscl = ff.hscale lscl = max([fun.size for fun in ff]) self.assertEqual(ff.funs.size, gg.funs.size) self.assertLessEqual(infnorm(gg(xx)-GG(xx)), vscl*hscl*lscl*tol) return tester
def unaryOpTester(f, unaryop, dom, tol): a, b = dom xx = linspace(a,b,1001) ff = Chebfun.initfun_adaptive(f, linspace(a,b,9)) GG = lambda x: unaryop(f(x)) gg = unaryop(ff) def tester(self): vscl = ff.vscale hscl = ff.hscale lscl = max([fun.size for fun in ff]) self.assertEqual(ff.funs.size, gg.funs.size) self.assertLessEqual(infnorm(gg(xx)-GG(xx)), vscl*hscl*lscl*tol) return tester
def test_rpow_constant(self): for ((_, _), (f, _)) in powtestfuns: for c in (1, 2, 3): for dom, _ in powtestdomains: a, b = dom xx = np.linspace(a, b, 1001) ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 11)) g = lambda x: c**f(x) gg = c**ff vscl = gg.vscale hscl = gg.hscale lscl = max([fun.size for fun in gg]) tol = 2 * abs(c) * vscl * hscl * lscl * eps self.assertLessEqual(infnorm(g(xx) - gg(xx)), tol)
def test_rpow_constant(self): for ((_,_), (f, _)) in powtestfuns: for c in (1, 2, 3): for dom, _ in powtestdomains: a,b = dom xx = np.linspace(a, b, 1001) ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 11)) g = lambda x: c ** f(x) gg = c ** ff vscl = gg.vscale hscl = gg.hscale lscl = max([fun.size for fun in gg]) tol = 2*abs(c)*vscl*hscl*lscl*eps self.assertLessEqual(infnorm(g(xx)-gg(xx)), tol)
def test__mul__rmul__constant(self): for (f, _, _) in testfunctions: for c in (-1, 1, 10, -1e5): for dom, _ in chebfun_testdomains: a, b = dom xx = np.linspace(a, b, 1001) ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 11)) g = lambda x: c * f(x) gg1 = c * ff gg2 = ff * c vscl = ff.vscale hscl = ff.hscale lscl = max([fun.size for fun in ff]) tol = 2 * abs(c) * vscl * hscl * lscl * eps self.assertLessEqual(infnorm(g(xx) - gg1(xx)), tol) self.assertLessEqual(infnorm(g(xx) - gg2(xx)), tol)
def test__mul__rmul__constant(self): for (f, _, _) in testfunctions: for c in (-1, 1, 10, -1e5): for dom, _ in chebfun_testdomains: a,b = dom xx = np.linspace(a, b, 1001) ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 11)) g = lambda x: c * f(x) gg1 = c * ff gg2 = ff * c vscl = ff.vscale hscl = ff.hscale lscl = max([fun.size for fun in ff]) tol = 2*abs(c)*vscl*hscl*lscl*eps self.assertLessEqual(infnorm(g(xx)-gg1(xx)), tol) self.assertLessEqual(infnorm(g(xx)-gg2(xx)), tol)
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)
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)
def test_truediv_constant(self): for (f, _, hasRoots) in testfunctions: for c in (-1, 1, 10, -1e5): for dom, _ in chebfun_testdomains: a, b = dom xx = np.linspace(a, b, 1001) ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 11)) g = lambda x: f(x) / c gg = ff / c vscl = gg.vscale hscl = gg.hscale lscl = max([fun.size for fun in gg]) tol = 2 * abs(c) * vscl * hscl * lscl * eps self.assertLessEqual(infnorm(g(xx) - gg(xx)), tol) # don't do the following test for functions with roots if not hasRoots: h = lambda x: c / f(x) hh = c / ff vscl = hh.vscale hscl = hh.hscale lscl = max([fun.size for fun in hh]) tol = 2 * abs(c) * vscl * hscl * lscl * eps self.assertLessEqual(infnorm(h(xx) - hh(xx)), tol)
def test_truediv_constant(self): for (f, _, hasRoots) in testfunctions: for c in (-1, 1, 10, -1e5): for dom, _ in chebfun_testdomains: a,b = dom xx = np.linspace(a, b, 1001) ff = Chebfun.initfun_adaptive(f, np.linspace(a, b, 11)) g = lambda x: f(x) / c gg = ff / c vscl = gg.vscale hscl = gg.hscale lscl = max([fun.size for fun in gg]) tol = 2*abs(c)*vscl*hscl*lscl*eps self.assertLessEqual(infnorm(g(xx)-gg(xx)), tol) # don't do the following test for functions with roots if not hasRoots: h = lambda x: c / f(x) hh = c / ff vscl = hh.vscale hscl = hh.hscale lscl = max([fun.size for fun in hh]) tol = 2*abs(c)*vscl*hscl*lscl*eps self.assertLessEqual(infnorm(h(xx)-hh(xx)), tol)
def setUp(self): f = lambda x: sin(4*x) + exp(cos(14*x)) - 1.4 self.f1 = Chebfun.initfun_adaptive(f, [-1,1]) self.f2 = Chebfun.initfun_adaptive(f, [-3,0,1]) self.f3 = Chebfun.initfun_adaptive(f, [-2,-0.3,1.2])
def test_empty(self): rts = Chebfun.initempty().roots() self.assertIsInstance(rts, np.ndarray) self.assertEqual(rts.size, 0)
def test_cumsum_empty(self): If = Chebfun.initempty().cumsum() self.assertIsInstance(If, Chebfun) self.assertTrue(If.isempty)
def test_dot_empty(self): emptyfun = Chebfun.initempty() self.assertEqual(self.f1.dot(emptyfun), 0) self.assertEqual(emptyfun.dot(self.f1), 0)
def test_diff_empty(self): df = Chebfun.initempty().diff() self.assertIsInstance(df, Chebfun) self.assertTrue(df.isempty)
def test_sum_empty(self): f = Chebfun.initempty() self.assertEqual(f.sum(), .0)
def setUp(self): f = lambda x: sin(x-.1) self.f1 = Chebfun.initfun_adaptive(f, [-2,0,3]) self.f2 = Chebfun.initfun_adaptive(f, np.linspace(-2,3,5))
def test_initempty(self): emptyfun = Chebfun.initempty() self.assertEqual(emptyfun.funs.size, 0)
def setUp(self): self.f0 = Chebfun.initempty() self.f1 = Chebfun.initfun_adaptive(lambda x: x**2, [-1,1]) self.f2 = Chebfun.initfun_adaptive(lambda x: x**2, [-1,0,1,2])
def _initfun(f, domain, n): if n is None: return Chebfun.initfun_adaptive(f, domain) else: return Chebfun.initfun_fixedlen(f, n, domain)
def setUp(self): self.emptyfun = Chebfun.initempty() self.yy = np.linspace(-1,1,2000)
def setUp(self): self.f0 = Chebfun.initempty() self.f1 = Chebfun.initfun_adaptive(lambda x: x**2, [-1, 1]) self.f2 = Chebfun.initfun_adaptive(lambda x: x**2, [-1, 0, 1, 2])