The Chebyshev polynomials of the first kind are defined for $x \in [-1, 1]$ as follows
$$\ T_n(x) = \cos(n \cdot \arccos(x))$$for $n=0,1,2,\dots$
See also:
Chebyshev polynomials of the first kind - MathWorld
Chebyshev polynomials - Wikipedia
In [1]:
import numpy as np
import matplotlib.pyplot as plt
In [2]:
x = np.linspace(-1,1, 2000)
In [3]:
M = 7
c = np.arange(0, M+1)
y = []
for N in c:
y.append(np.cos(N * np.arccos(x)))
# Here y[n] is the n-th Chebyshev polynomial i.e. it is Tn(x)
# Tn(x) = cos(N * arccos(x))
# for x in the closed interval [-1, 1]
In [4]:
c
Out[4]:
array([0, 1, 2, 3, 4, 5, 6, 7])
In [5]:
fig, ax = plt.subplots(figsize=(11,7))
for i in c:
ax.plot(x, y[i], linewidth=2.0, label='$T_' + str(i) + '(x)$')
ax.set(xlim=(-1.05, 1.5),
ylim=(-1.1, 1.1))
plt.grid(True, linestyle='--')
plt.legend(loc='lower right')
plt.show()
In [6]:
# Tn(x) takes values of +1 or -1 in these points
# (n>=1)
def extremum_points(N):
m = np.arange(N, -1, -1) # N, N-1, N-2, ... , 2, 1, 0
x = np.cos(m*np.pi / N)
return x
# Tn(x) takes a value of 0 in these points
# (n>=1)
def root_points(N):
m = np.arange(N, 0, -1) # N, N-1, N-2, ... , 2, 1
x = np.cos((2*m-1)*np.pi / (2*N))
return x
In [7]:
extremum_points(5)
Out[7]:
array([-1. , -0.80901699, -0.30901699, 0.30901699, 0.80901699, 1. ])
In [8]:
root_points(5)
Out[8]:
array([-9.51056516e-01, -5.87785252e-01, 6.12323400e-17, 5.87785252e-01, 9.51056516e-01])
In [9]:
N = 5
y = np.cos(N*np.arccos(extremum_points(N)))
y
Out[9]:
array([-1., 1., -1., 1., -1., 1.])
In [10]:
N = 5
y = np.cos(N*np.arccos(root_points(N)))
y
Out[10]:
array([ 5.5109106e-16, -4.2862638e-16, 3.0616170e-16, -1.8369702e-16, -8.2694608e-16])
In [11]:
N = 10
y = np.cos(N*np.arccos(extremum_points(N)))
y
Out[11]:
array([ 1., -1., 1., -1., 1., -1., 1., -1., 1., -1., 1.])
In [12]:
N = 10
y = np.cos(N*np.arccos(root_points(N)))
y
Out[12]:
array([-6.49248498e-15, -7.35407060e-16, -2.69484194e-15, -9.80336420e-16, -2.44991258e-15, 5.51091060e-16, -4.28626380e-16, 3.06161700e-16, -1.07187544e-15, 2.72576760e-15])
No comments:
Post a Comment