def test_polynomial_interpolates_to_itself(self): def f(x): return 4*x**3 + 2*x + 1 x_knots = [x for x in range(-2,2)] p = newton.interpolation_polynomial([(x,f(x)) for x in x_knots]) self.assertEqual(p(0.5), f(0.5))
def test_zero_degree_polynomial(self): """Are zero degree (constant) polynomials handled correctly?""" # f(x) = 2 p, p_str = newton.interpolation_polynomial([(0,2)], get_string=True) self.assertEqual(p(-3.14), 2) self.assertEqual(p_str, 'p(x) = 2')
def test_known_points_equal_themselves(self): # f(x) = 2x x_knots = range(1,5) p = newton.interpolation_polynomial([(x,2*x) for x in x_knots]) for x in x_knots: self.assertEqual(p(x), 2*x)