Fitting in Chebyshev basisΒΆ

Plot noisy data and their polynomial fit in a Chebyshev basis

../../../_images/sphx_glr_plot_chebyfit_001.png
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
x = np.linspace(-1, 1, 2000)
y = np.cos(x) + 0.3*np.random.rand(2000)
p = np.polynomial.Chebyshev.fit(x, y, 90)
t = np.linspace(-1, 1, 200)
plt.plot(x, y, 'r.')
plt.plot(t, p(t), 'k-', lw=3)
plt.show()

Total running time of the script: ( 0 minutes 0.200 seconds)

Generated by Sphinx-Gallery