# Matlab script plot_Runge_and_Lagrange_interpolant.m # Accompanying program for the text # # Classical and Modern Numerical Analysis: # Theory, Methods and Practice # by Azmy S. Ackleh, Edward J. Allen, # R. Baker Kearfott, and Padmanabhan Seshaiyer # # (Taylor and Francis / CRC Press, 2009) # # This script first computes the coefficients of the degree 10 Lagrange # interpolating polynomial (in terms of powers of x) with equally spaced # points over the interval -5 to 5 to Runge's function, then plots both # the values of this interpolating polynomial and the values of Runge's # function with 200 equally spaced points on the interval [-5,5]. from Lagrange_interp_poly_coeffs import Lagrange_interp_poly_coeffs from Lagrange_interp_poly_val import Lagrange_interp_poly_val from runge import runge import numpy as np import matplotlib.pyplot as plt a = Lagrange_interp_poly_coeffs(10,runge,-5,5) xpts = np.linspace(-5,5,200) z1 = Lagrange_interp_poly_val(a,xpts) z2 = runge(xpts) plt.plot(xpts,z1,xpts,z2) xp = np.linspace(-5,5,11) plt.plot(xp,runge(xp),'o',markersize=10, alpha=0.5) plt.xlim(-5,5) plt.ylim(-1,2) plt.grid() plt.show()