Esempio n. 1
0
 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))
Esempio n. 2
0
File: ui.py Progetto: nbren12/chebpy
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)
Esempio n. 3
0
 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))
Esempio n. 4
0
File: ui.py Progetto: chebpy/chebpy
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)
Esempio n. 5
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)
Esempio n. 6
0
 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))
Esempio n. 7
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)
Esempio n. 8
0
 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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
0
 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)
Esempio n. 15
0
 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)
Esempio n. 16
0
File: ui.py Progetto: nbren12/chebpy
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)
Esempio n. 17
0
 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)
Esempio n. 18
0
 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)
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
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)
Esempio n. 22
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)
Esempio n. 23
0
 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)
Esempio n. 24
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)
Esempio n. 25
0
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
Esempio n. 26
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)
Esempio n. 27
0
 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)
Esempio n. 28
0
 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)
Esempio n. 29
0
 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))
Esempio n. 30
0
 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)     
Esempio n. 31
0
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
Esempio n. 32
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)
Esempio n. 33
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)
Esempio n. 34
0
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
Esempio n. 35
0
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
Esempio n. 36
0
 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)
Esempio n. 37
0
 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)
Esempio n. 38
0
 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)
Esempio n. 39
0
 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)
Esempio n. 40
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)
Esempio n. 41
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)
Esempio n. 42
0
 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)
Esempio n. 43
0
 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)
Esempio n. 44
0
 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])
Esempio n. 45
0
 def test_empty(self):
     rts = Chebfun.initempty().roots()
     self.assertIsInstance(rts, np.ndarray)
     self.assertEqual(rts.size, 0)
Esempio n. 46
0
 def test_empty(self):
     rts = Chebfun.initempty().roots()
     self.assertIsInstance(rts, np.ndarray)
     self.assertEqual(rts.size, 0)
Esempio n. 47
0
 def test_cumsum_empty(self):
     If = Chebfun.initempty().cumsum()
     self.assertIsInstance(If, Chebfun)
     self.assertTrue(If.isempty)
Esempio n. 48
0
 def test_dot_empty(self):
     emptyfun = Chebfun.initempty()
     self.assertEqual(self.f1.dot(emptyfun), 0)
     self.assertEqual(emptyfun.dot(self.f1), 0)
Esempio n. 49
0
 def test_diff_empty(self):
     df = Chebfun.initempty().diff()
     self.assertIsInstance(df, Chebfun)
     self.assertTrue(df.isempty)
Esempio n. 50
0
 def test_cumsum_empty(self):
     If = Chebfun.initempty().cumsum()
     self.assertIsInstance(If, Chebfun)
     self.assertTrue(If.isempty)
Esempio n. 51
0
 def test_sum_empty(self):
     f = Chebfun.initempty()
     self.assertEqual(f.sum(), .0)
Esempio n. 52
0
 def test_diff_empty(self):
     df = Chebfun.initempty().diff()
     self.assertIsInstance(df, Chebfun)
     self.assertTrue(df.isempty)
Esempio n. 53
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))
Esempio n. 54
0
 def test_initempty(self):
     emptyfun = Chebfun.initempty()
     self.assertEqual(emptyfun.funs.size, 0)
Esempio n. 55
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])
Esempio n. 56
0
 def test_sum_empty(self):
     f = Chebfun.initempty()
     self.assertEqual(f.sum(), .0)
Esempio n. 57
0
File: ui.py Progetto: 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)
Esempio n. 58
0
 def setUp(self):
     self.emptyfun = Chebfun.initempty()
     self.yy = np.linspace(-1,1,2000)
Esempio n. 59
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])
Esempio n. 60
0
 def test_dot_empty(self):
     emptyfun = Chebfun.initempty()
     self.assertEqual(self.f1.dot(emptyfun), 0)
     self.assertEqual(emptyfun.dot(self.f1), 0)