from numpy import *
from scipy import linalg
from scipy.linalg import norm
from matplotlib.pyplot import *
from prettytable import PrettyTable
from timeit import default_timer as timer
import sys
sys.path.append('fncbook/')
import fncbook as FNC
# This (optional) block is for improving the display of plots.
# from IPython.display import set_matplotlib_formats
# set_matplotlib_formats("svg","pdf")
# %config InlineBackend.figure_format = 'svg'
rcParams["figure.figsize"] = [7, 4]
rcParams["lines.linewidth"] = 2
rcParams["lines.markersize"] = 4
rcParams['animation.html'] = "jshtml" # or try "html5"
With barycentric interpolation available in the form of Function 9.2.1, we can explore polynomial interpolation using a numerically stable algorithm. Any remaining sensitivity to error is due to the conditioning of the interpolation process itself.
The disappointing loss of convergence in Example 9.3.1 is a sign of ill conditioning due to the use of equally spaced nodes. We will examine this effect using the error formula (9.1.6) as a guide:
While the dependence on f is messy here, the error indicator Φ(x) can be studied as a function of the nodes only.
Two observations from the result of Example 9.3.2 are important. First, ∣Φ∣ decreases exponentially at each fixed location in the interval (note that the spacing between curves is constant for constant increments of n). Second, ∣Φ∣ is larger at the ends of the interval than in the middle, by an exponentially growing factor. This gap is what can ruin the convergence of polynomial interpolation.
The observation of instability in Example 9.3.3 is known as the Runge phenomenon. The Runge phenomenon is an instability manifested when the nodes of the interpolant are equally spaced and the degree of the polynomial increases. We reiterate that the phenomenon is rooted in the interpolation convergence theory and not a consequence of the algorithm chosen to implement polynomial interpolation.
Significantly, the convergence observed in Example 9.3.3 is stable within a middle portion of the interval. By redistributing the interpolation nodes, we will next sacrifice a little of the convergence in the middle portion in order to improve it near the ends and rescue the process globally.
The observations above hint that we might find success by having more nodes near the ends of the interval than in the middle. Though we will not give the details, it turns out that there is a precise asymptotic sense in which this must be done to make polynomial interpolation work over the entire interval. One especially important node family that gives stable convergence for polynomial interpolation is the Chebyshev points of the second kind (or Chebyshev extreme points) defined by
These are the projections onto the x-axis of n+1 equally spaced points on a unit circle. They are densely clustered near the ends of [−1,1], and this feature turns out to overcome the Runge phenomenon.
As a bonus, for Chebyshev nodes the barycentric weights are simple:
If we take n→∞ and use polynomial interpolation on Chebyshev nodes, the convergence rate is exponential in n. The following is typical of the results that can be proved.
The condition “f is analytic” means that the Taylor series of f converges to f(x) in an open interval containing [−1,1].[1] A necessary condition of analyticity is that f is infinitely differentiable.
In other contexts we refer to (9.3.4) as linear convergence, but here it is usual to say that the rate is exponential or that one has spectral convergence. It achieves constant reduction factors in the error by constant increments of n. By contrast, algebraic convergence in the form O(n−p) for some p>0 requires multiplyingn by a constant factor in order to reduce error by a constant factor. Graphically, spectral error is a straight line on a log-linear scale, while algebraic convergence is a straight line on a log-log scale.