def test_wrapper(self): P = KroghInterpolator(self.xs, self.ys) assert_almost_equal(P(self.test_xs), krogh_interpolate(self.xs, self.ys, self.test_xs)) assert_almost_equal(P.derivative(self.test_xs, 2), krogh_interpolate(self.xs, self.ys, self.test_xs, der=2)) assert_almost_equal( P.derivatives(self.test_xs, 2), krogh_interpolate(self.xs, self.ys, self.test_xs, der=[0, 1]) )
def test_wrapper(self): P = KroghInterpolator(self.xs, self.ys) assert_almost_equal(P(self.test_xs), krogh_interpolate(self.xs, self.ys, self.test_xs)) assert_almost_equal( P.derivative(self.test_xs, 2), krogh_interpolate(self.xs, self.ys, self.test_xs, der=2)) assert_almost_equal( P.derivatives(self.test_xs, 2), krogh_interpolate(self.xs, self.ys, self.test_xs, der=[0, 1]))
def my_interpolate(ts, ys, n_interp, use_y_np1_in_interp=False): # Find the start and end of the slice of ts, ys that we want to use for # interpolation. start = -n_interp if use_y_np1_in_interp else -n_interp - 1 end = None if use_y_np1_in_interp else -1 # Nasty things could go wrong if you try to start adapting with not # enough points because [-a:-b] notation lets us go past the ends of # the list without throwing an error! Check it! assert len(ts[start:end]) == n_interp # Actually interpolate the values t_nph = (ts[-1] + ts[-2]) / 2 t_nmh = (ts[-2] + ts[-3]) / 2 interps = krogh_interpolate(ts[start:end], ys[start:end], [t_nmh, ts[-2], t_nph], der=[0, 1, 2]) # Unpack (can't get "proper" unpacking to work) dy_nmh = interps[1][0] dy_n = interps[1][1] y_nph = interps[0][2] dy_nph = interps[1][2] ddy_nph = interps[2][2] return dy_nmh, y_nph, dy_nph, ddy_nph, dy_n
def my_interpolate(ts, ys, n_interp, use_y_np1_in_interp=False): # Find the start and end of the slice of ts, ys that we want to use for # interpolation. start = -n_interp if use_y_np1_in_interp else -n_interp - 1 end = None if use_y_np1_in_interp else -1 # Nasty things could go wrong if you try to start adapting with not # enough points because [-a:-b] notation lets us go past the ends of # the list without throwing an error! Check it! assert len(ts[start:end]) == n_interp # Actually interpolate the values t_nph = (ts[-1] + ts[-2])/2 t_nmh = (ts[-2] + ts[-3])/2 interps = krogh_interpolate( ts[start:end], ys[start:end], [t_nmh, ts[-2], t_nph], der=[0, 1, 2]) # Unpack (can't get "proper" unpacking to work) dy_nmh = interps[1][0] dy_n = interps[1][1] y_nph = interps[0][2] dy_nph = interps[1][2] ddy_nph = interps[2][2] return dy_nmh, y_nph, dy_nph, ddy_nph, dy_n