当前位置: 首页>>代码示例>>Python>>正文


Python Chebfun.from_function方法代码示例

本文整理汇总了Python中pychebfun.Chebfun.from_function方法的典型用法代码示例。如果您正苦于以下问题:Python Chebfun.from_function方法的具体用法?Python Chebfun.from_function怎么用?Python Chebfun.from_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pychebfun.Chebfun的用法示例。


在下文中一共展示了Chebfun.from_function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_add(self):
     s = Chebfun.from_function(np.sin)
     c = Chebfun.from_function(np.cos)
     r = c + s
     def expected(x):
         return np.sin(x) + np.cos(x)
     tools.assert_close(r, expected)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:9,代码来源:test_chebfun.py

示例2: test_truncate

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_truncate(self, N=17):
     """
     Check that the Chebyshev coefficients are properly truncated.
     """
     small = Chebfun.from_function(tools.f, N=N)
     new = Chebfun.from_function(small)
     self.assertEqual(new.size(), small.size(),)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:9,代码来源:test_chebfun.py

示例3: a

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
def a(p, order):
    if p > 0:
        return Chebfun.from_function(lambda x: sqrt(2)* np.sin(p*x)/p,[0,pi])\
                      .differentiate(order)
    else:
        if order == 1:
            return Chebfun.from_function(lambda x: np.ones_like(x), [0, pi])
        else:
            return Chebfun.from_function(lambda x: np.zeros_like(x), [0, pi])
开发者ID:nbren12,项目名称:gnl,代码行数:11,代码来源:galerkin.py

示例4: test_highdiff

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_highdiff(self):
     """
     Higher order derivatives of exp(x)
     """
     e = Chebfun.from_function(lambda x:np.exp(x))
     e4 = e.differentiate(4)
     tools.assert_close(e4, e)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:9,代码来源:test_chebfun.py

示例5: test_init

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
def test_init(ufunc):
    xx = Chebfun.from_function(lambda x: x,[0.25,0.75])
    ff = ufunc(xx)
    assert isinstance(ff, Chebfun)
    result = ff.values()
    expected = ufunc(ff._ui_to_ab(ff.p.xi))
    npt.assert_allclose(result, expected)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:9,代码来源:test_domain.py

示例6: test_sum

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_sum(self):
     """
     Integral of chebfun of x**2 on [-1,1] is 2/3
     """
     p = Chebfun.from_function(Quad)
     i = p.sum()
     npt.assert_array_almost_equal(i,2/3)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:9,代码来源:test_chebfun.py

示例7: test_diffquad

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_diffquad(self):
     """
     Derivative of Chebfun(x**2/2) is close to identity function
     """
     self.p = .5*Chebfun.from_function(Quad)
     X = self.p.differentiate()
     tools.assert_close(X, lambda x:x)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:9,代码来源:test_chebfun.py

示例8: test_nonzero

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_nonzero(self):
     """
     nonzero is True for Chebfun(f) and False for Chebfun(0)
     """
     self.assertTrue(self.p)
     mp = Chebfun.from_function(tools.Zero)
     self.assertFalse(mp)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:9,代码来源:test_chebfun.py

示例9: test_scalarvectormult

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_scalarvectormult(self):
     """
     Possible to multiply scalar with vector chebfun.
     """
     v = Chebfun.from_function(segment)
     s = np.sin(Chebfun.identity())
     m = s * v
     tools.assert_close(m[0], s*v[0])
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:10,代码来源:test_chebfun.py

示例10: test_slice

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_slice(self):
     """
     Test slicing: f[0] should return the first component.
     """
     s = Chebfun.from_function(segment)
     tools.assert_close(s[0], Chebfun.identity())
     tools.assert_close(s[1], Chebfun(0.))
     tools.assert_close(s[:], s)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:10,代码来源:test_chebfun.py

示例11: test_integrate

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_integrate(self):
     """
     Integrate exp
     """
     e = Chebfun.from_function(lambda x:np.exp(x))
     antideriv = e.integrate()
     result = antideriv - antideriv(antideriv._domain[0])
     tools.assert_close(result, e - e(antideriv._domain[0]))
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:10,代码来源:test_chebfun.py

示例12: test_runge

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_runge(self):
     """
     Test some of the capabilities of operator overloading.
     """
     r = Chebfun.from_function(runge)
     x = Chebfun.basis(1)
     rr = 1./(1+25*x**2)
     tools.assert_close(r, rr, rtol=1e-13)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:10,代码来源:test_chebfun.py

示例13: test_diff_x

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_diff_x(self):
     """
     First and second derivative of Chebfun(x) are close to one and zero respectively.
     """
     self.p = Chebfun.from_function(tools.Identity)
     one = self.p.differentiate()
     zero = one.differentiate()
     npt.assert_allclose(one(tools.xs), 1.)
     npt.assert_allclose(tools.Zero(tools.xs), 0.)
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:11,代码来源:test_chebfun.py

示例14: test_dot

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_dot(self):
     """
     f.0 = 0
     f.1 = f.sum()
     """
     p = Chebfun.from_function(np.sin)
     z = p.dot(Chebfun(0.))
     self.assertAlmostEqual(z, 0.)
     s = p.dot(Chebfun(1.))
     self.assertAlmostEqual(s, p.sum())
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:12,代码来源:test_chebfun.py

示例15: test_N

# 需要导入模块: from pychebfun import Chebfun [as 别名]
# 或者: from pychebfun.Chebfun import from_function [as 别名]
 def test_N(self):
     """
     Check initialisation with a fixed N
     """
     N = self.p.size() - 1
     pN = Chebfun.from_function(tools.f, N=N)
     self.assertEqual(len(pN.coefficients()), N+1)
     self.assertEqual(len(pN.coefficients()),pN.size())
     tools.assert_close(pN, self.p)
     npt.assert_allclose(pN.coefficients(),self.p.coefficients())
开发者ID:olivierverdier,项目名称:pychebfun,代码行数:12,代码来源:test_chebfun.py


注:本文中的pychebfun.Chebfun.from_function方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。