最佳平方逼近之构造基底——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:
在这里插入图片描述

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值