切比雪夫多项式拟合

 

 

 

 

切比雪夫多项式拟合,个人理解就是用其可以来拟合一个函数,如下面例子中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值\t", "拟合的y值\t", "实际的y值\t")
for v in x:
        print( v, np.polynomial.Chebyshev(c)(v), np.cos(v))

 

结果:

 

 

 

 

 

 

 

=====================================================

 

参考:

http://liao.cpython.org/scipy09/

 

posted on 2021-06-06 20:28  Angry_Panda  阅读(2752)  评论(0编辑  收藏  举报

导航