# Jump with Chebyshev Nodes

In [23]:
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as pt
import scipy.special as sps

In [32]:
n = 50

k = np.arange(1, n+1, dtype=np.float64)

cheb_nodes = np.cos((2*k-1)/(2*n)*np.pi)
pt.plot(cheb_nodes, 0*cheb_nodes, "o")

Out[32]:
[<matplotlib.lines.Line2D at 0x7f2f49f716a0>]


Build the Vandermonde matrix for orthogonal polynomials with Chebyshev nodes:

In [35]:
V = np.array([
sps.eval_legendre(i, cheb_nodes)
for i in range(n)
]).T

la.cond(V)

Out[35]:
13.082290511123739


Notice the condition number of the Vandermonde matrix! How does that compare to our prior ones?

In [36]:
def f(x):
return (x>=0).astype(np.float64)

In [37]:
coeffs = la.solve(V, f(cheb_nodes))

In [38]:
x = np.linspace(-1, 1, 1000)

In [39]:
interpolant = 0
for i in range(n):
interpolant += coeffs[i]*sps.eval_legendre(i, x)

In [41]:
pt.plot(x, interpolant)
pt.plot(x, f(x), "--", color="gray")

Out[41]:
[<matplotlib.lines.Line2D at 0x7f2f49edbbe0>]

In []: