最佳平方逼近之构造基底——matlab实现

作者:老李
日期:10-30

目标:
1.构造Legendre基函数作为基底
2.构造Chebyshev基函数作为基底

过程:
构造Legendre多项式函数作为基底

function [ L ] = LegendreBases( n,a,b )
%LegendreBases: crate the basis of chebyshev functional space 
%Input:        n: the number of bases of this functional space
%              a: left end of the interval
%              b: right end of the interval
%Output:       C: the basis of chebyshev functional space
syms x;
A = sym(zeros(1,n));
A(1) = 1;
A(2) = x;
for i = 1:n-2
    A(i+2) =((2*i+3)*x*A(i+1)-n*A(i))/(i+2);
end
L = 0.5*((b-a).*A)+0.5*(a+b);
end

构造Chebyshev多项式函数作为基底

function [ C ] = chebyshevBases( n,a,b )
%chebyshevBases: crate the basis of chebyshev functional space 
%Input:        n: the number of bases of this functional space
%              a: left end of the interval
%              b: right end of the interval
%Output:       C: the basis of chebyshev functional space
syms x;
A = sym(zeros(1,n));
A(1) = 1;
A(2) = x;
for i = 1:n-2
    A(i+2) = 2*x*A(i+1) - A(i);
end
C = 0.5*((b-a).*A)+0.5*(a+b);
end

我们随意构造一些节点用于逼近:

X = [11 15 17 12 22 29 24 23 34 31]
Y = [42 56 12 47 56 32 18 5 44 23]

然后我们使用10个基函数,区间为[10,35],带入到最佳平方逼近函数中,函数在我的上一篇博客有写。
传送门:https://blog.csdn.net/weixin_29732003/article/details/102689271

然后我们得到了如下效果:

Legendre:
在这里插入图片描述
Chebyshev:
在这里插入图片描述
这也说明了插值函数具有唯一性

我们改用5个基函数作为基底,效果如下:
Legendre:
在这里插入图片描述
Chebyshev:
在这里插入图片描述

感觉很一样,让我们看看误差
Chebyshev:

Legendre:
在这里插入图片描述

结果发现一模一样。
任一正交基底运用最佳二乘逼近,如果运用的是同意数量的基底,其最终拟合出来的结果,是否具有唯一性呢。

发布了31 篇原创文章 · 获赞 6 · 访问量 2812

猜你喜欢

转载自blog.csdn.net/weixin_29732003/article/details/102824650