Chebyshev polynomials

In [1]:
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as pt

Part I: Plotting the Chebyshev polynomials

In [4]:
x = np.linspace(-1, 1, 100)

pt.xlim([-1.2, 1.2])
pt.ylim([-1.2, 1.2])

for k in range(10): # crank up
    pt.plot(x, np.cos(k*np.arccos(x)))

Part II: Understanding the Nodes

What if we interpolate random data?

In [11]:
n = 50 # crank up

i = np.arange(n, dtype=np.float64)

# Chebyshev nodes:
#nodes = np.cos((2*(i+1)-1)/(2*n)*np.pi)

# Equispace nodes:
nodes = np.linspace(-1, 1, n)
In [12]:
pt.plot(nodes, 0*nodes, "o")
Out[12]:
[<matplotlib.lines.Line2D at 0x7faf089ab160>]

Part III: Chebyshev Interpolation

In [13]:
V = np.cos(i*np.arccos(nodes.reshape(-1, 1)))
data = np.random.randn(n)
coeffs = la.solve(V, data)
In [14]:
x = np.linspace(-1, 1, 1000)
Vfull = np.cos(i*np.arccos(x.reshape(-1, 1)))
pt.plot(x, np.dot(Vfull, coeffs))
pt.plot(nodes, data, "o")
Out[14]:
[<matplotlib.lines.Line2D at 0x7faf08b9f4a8>]

Part IV: Conditioning

In [ ]:
n = 10 # crank up

i = np.arange(n, dtype=np.float64)
nodes = np.cos((2*(i+1)-1)/(2*n)*np.pi)
V = np.cos(i*np.arccos(nodes.reshape(-1, 1)))

la.cond(V)
In [ ]: