示例#1
0
 def check_linear_1d(self):
     x = [1,2,3]
     y = [0,2,4]
     lut = UnivariateSpline(x,y,k=1)
     assert_array_almost_equal(lut.get_knots(),[1,3])
     assert_array_almost_equal(lut.get_coeffs(),[0,4])
     assert_almost_equal(lut.get_residual(),0.0)
     assert_array_almost_equal(lut([1,1.5,2]),[0,1,2])
示例#2
0
def demo1():
    x = arange(0,2*pi+pi/4,2*pi/8)
    xnew = arange(-pi/10,2*pi+pi/4+pi/10,pi/50)
    y = sin(x)


    def make_plot():
        xplt.plot(x,y,'x',xnew,spline(xnew),x,y,'b',xnew,sin(xnew),
                  spline.get_knots(),spline(spline.get_knots()),'o')

    spline = UnivariateSpline(x,y,k=1)
    assert isinstance(spline,LSQUnivariateSpline)
    print 'Linear LSQ approximation of sin(x):',spline.__class__.__name__
    make_plot()
    print 'Residual=',spline.get_residual()
    raw_input('Press any key to continue..')

    spline.set_smoothing_factor(0)
    assert isinstance(spline,InterpolatedUnivariateSpline)
    print 'Linear interpolation of sin(x):',spline.__class__.__name__
    make_plot()
    print 'Residual=',spline.get_residual()
    raw_input('Press any key to continue..')

    spline = UnivariateSpline(x,y,k=1,s=0.1)
    print 'Linear smooth approximation of sin(x):',spline.__class__.__name__
    assert isinstance(spline,UnivariateSpline)
    make_plot()
    print 'Residual=',spline.get_residual()
    raw_input('Press any key to continue..')