切比雪夫多项式拟合,个人理解就是用其可以来拟合一个函数,如下面例子中x为1,2,3,4时,对应的y为1,3,5,4,我们用契比雪夫多项式拟合来表示这样的一个函数。
例子:
import numpy.polynomial.chebyshev as chebyshev import numpy as np import numpy.linalg as linalg x = np.array([1, 2, 3, 4]) y = np.array([1, 3, 5, 4]) deg = len(x) - 1 A = chebyshev.chebvander(x, deg) print(A, "# A") c = linalg.solve(A, y) print(c,"# c") for v in x: print( v, np.polynomial.Chebyshev(c)(v),"#p(%d)" % v)
结果:
-----------------------------------------------------------------------------------------------------------
例子2:
根据输入x,拟合函数 cos(x)
import numpy.polynomial.chebyshev as chebyshev import numpy as np import numpy.linalg as linalg x = np.linspace(0,1,10) y = np.cos(x) deg = len(x) - 1 A = chebyshev.chebvander(x, deg) print(A, "# A") c = linalg.solve(A, y) print(c,"# c") print("x值 ", "拟合的y值 ", "实际的y值 ") for v in x: print( v, np.polynomial.Chebyshev(c)(v), np.cos(v))
结果:
=====================================================
参考: