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


Python PPoly.from_spline方法代码示例

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


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

示例1: test_ppoly

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_ppoly(self):
        b = _make_random_spline()
        t, c, k = b.tck
        pp = PPoly.from_spline((t, c, k))

        xx = np.linspace(t[k], t[-k], 100)
        assert_allclose(b(xx), pp(xx), atol=1e-14, rtol=1e-14)
开发者ID:Brucechen13,项目名称:scipy,代码行数:9,代码来源:test_bsplines.py

示例2: test_integrate_ppoly

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_integrate_ppoly(self):
        # test .integrate method to be consistent with PPoly.integrate
        x = [0, 1, 2, 3, 4]
        b = make_interp_spline(x, x)
        b.extrapolate = 'periodic'
        p = PPoly.from_spline(b)

        for x0, x1 in [(-5, 0.5), (0.5, 5), (-4, 13)]:
            assert_allclose(b.integrate(x0, x1),
                            p.integrate(x0, x1))
开发者ID:Brucechen13,项目名称:scipy,代码行数:12,代码来源:test_bsplines.py

示例3: test_from_spline

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_from_spline(self):
        np.random.seed(1234)
        x = np.sort(np.r_[0, np.random.rand(11), 1])
        y = np.random.rand(len(x))

        spl = splrep(x, y, s=0)
        pp = PPoly.from_spline(spl)

        xi = np.linspace(0, 1, 200)
        assert_allclose(pp(xi), splev(xi, spl))
开发者ID:AGPeddle,项目名称:scipy,代码行数:12,代码来源:test_interpolate.py

示例4: test_roots

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_roots(self):
        x = np.linspace(0, 1, 31)**2
        y = np.sin(30*x)

        spl = splrep(x, y, s=0, k=3)
        pp = PPoly.from_spline(spl)

        r = pp.roots()
        r = r[(r >= 0) & (r <= 1)]
        assert_allclose(r, sproot(spl), atol=1e-15)
开发者ID:AGPeddle,项目名称:scipy,代码行数:12,代码来源:test_interpolate.py

示例5: test_derivative_eval

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_derivative_eval(self):
        np.random.seed(1234)
        x = np.sort(np.r_[0, np.random.rand(11), 1])
        y = np.random.rand(len(x))

        spl = splrep(x, y, s=0)
        pp = PPoly.from_spline(spl)

        xi = np.linspace(0, 1, 200)
        for dx in range(0, 3):
            assert_allclose(pp(xi, dx), splev(xi, spl, dx))
开发者ID:AGPeddle,项目名称:scipy,代码行数:13,代码来源:test_interpolate.py

示例6: test_derivative

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_derivative(self):
        np.random.seed(1234)
        x = np.sort(np.r_[0, np.random.rand(11), 1])
        y = np.random.rand(len(x))

        spl = splrep(x, y, s=0, k=5)
        pp = PPoly.from_spline(spl)

        xi = np.linspace(0, 1, 200)
        for dx in range(0, 10):
            assert_allclose(pp(xi, dx), pp.derivative(dx)(xi),
                            err_msg="dx=%d" % (dx,))
开发者ID:AGPeddle,项目名称:scipy,代码行数:14,代码来源:test_interpolate.py

示例7: test_antiderivative_vs_spline

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_antiderivative_vs_spline(self):
        np.random.seed(1234)
        x = np.sort(np.r_[0, np.random.rand(11), 1])
        y = np.random.rand(len(x))

        spl = splrep(x, y, s=0, k=5)
        pp = PPoly.from_spline(spl)

        for dx in range(0, 10):
            pp2 = pp.antiderivative(dx)
            spl2 = splantider(spl, dx)

            xi = np.linspace(0, 1, 200)
            assert_allclose(pp2(xi), splev(xi, spl2),
                            rtol=1e-7)
开发者ID:AGPeddle,项目名称:scipy,代码行数:17,代码来源:test_interpolate.py

示例8: test_integrate

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_integrate(self):
        np.random.seed(1234)
        x = np.sort(np.r_[0, np.random.rand(11), 1])
        y = np.random.rand(len(x))

        spl = splrep(x, y, s=0, k=5)
        pp = PPoly.from_spline(spl)

        a, b = 0.3, 0.9
        ig = pp.integrate(a, b)

        ipp = pp.antiderivative()
        assert_allclose(ig, ipp(b) - ipp(a))
        assert_allclose(ig, splint(a, b, spl))

        a, b = -0.3, 0.9
        ig = pp.integrate(a, b, extrapolate=True)
        assert_allclose(ig, ipp(b) - ipp(a))

        assert_(np.isnan(pp.integrate(a, b, extrapolate=False)).all())
开发者ID:AGPeddle,项目名称:scipy,代码行数:22,代码来源:test_interpolate.py

示例9: test_antiderivative_vs_derivative

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
    def test_antiderivative_vs_derivative(self):
        np.random.seed(1234)
        x = np.linspace(0, 1, 30)**2
        y = np.random.rand(len(x))
        spl = splrep(x, y, s=0, k=5)
        pp = PPoly.from_spline(spl)

        for dx in range(0, 10):
            ipp = pp.antiderivative(dx)

            # check that derivative is inverse op
            pp2 = ipp.derivative(dx)
            assert_allclose(pp.c, pp2.c)

            # check continuity
            for k in range(dx):
                pp2 = ipp.derivative(k)

                r = 1e-13
                endpoint = r*pp2.x[:-1] + (1 - r)*pp2.x[1:]

                assert_allclose(pp2(pp2.x[1:]), pp2(endpoint),
                                rtol=1e-7, err_msg="dx=%d k=%d" % (dx, k))
开发者ID:AGPeddle,项目名称:scipy,代码行数:25,代码来源:test_interpolate.py

示例10: splrep

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import from_spline [as 别名]
from scipy.interpolate import PPoly
from scipy.interpolate import splev, splrep

W = np.array([-2.0, -2.5, -3.7538003, -5.00760061, -5.50760061])

tvec = np.linspace(0, 1, W.shape[0])

W = np.hstack((W[0], W[0], W[:], W[-1] - 0.1, W[-1] - 0.2))
tvec = np.hstack((-0.1, -0.05, tvec, 1.05, 1.1))

tck = splrep(tvec, W, s=0, k=3)

x2 = np.linspace(0, 1, 100)
# x2 = np.linspace(tvec[0], tvec[-1], 100)
y2 = splev(x2, tck)

print splev(0, tck)
print splev(0, tck, der=1)
print splev(1, tck, der=1)

poly = PPoly.from_spline(tck)
dpoly = poly.derivative(1)
ddpoly = poly.derivative(2)

[B, idx] = np.unique(poly.x, return_index=True)
coeff = poly.c[:, idx]


plt.plot(tvec, W, "o", x2, y2)
plt.show()
开发者ID:orthez,项目名称:openrave-forcefields,代码行数:32,代码来源:interpolate.py


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