示例#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))
示例#2
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))
示例#3
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))
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
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)
示例#9
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
示例#10
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
示例#11
0
 def test_initfun_adaptive_continuous_domain(self):
     ff = Chebfun.initfun_adaptive(self.f, [-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)
示例#12
0
 def test_initfun_adaptive_continuous_domain(self):
     ff = Chebfun.initfun_adaptive(self.f, [-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)
示例#13
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)
示例#14
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)
示例#15
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
示例#16
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)
示例#17
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))
示例#18
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
示例#19
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)
示例#20
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)
示例#21
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
示例#22
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
示例#23
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)
示例#24
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)
示例#25
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)
示例#26
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)
示例#27
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)
示例#28
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)
示例#29
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)
示例#30
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])
示例#31
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))
示例#32
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])
示例#33
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))
示例#34
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])
示例#35
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])
示例#36
0
 def test_initfun_adaptive_empty_domain(self):
     f = Chebfun.initfun_adaptive(self.f, domain=[])
     self.assertTrue(f.isempty)