数值逼近课程设计(1)——runge现象

    技术2022-07-11  86

    问题背景

    在数值分析领域中,Runge现象是在一组等间插值点上使用具有高次多项式的多项式插值时出现的区间边缘处的振荡问题。 它是由卡尔·龙格(Runge)在探索使用多项式插值逼近某些函数时的错误行为时发现的。这一发现非常重要,因为它表明使用高次多项式插值并不总能提高准确性。该现象与傅里叶级数近似中的吉布斯现象相似。

    数值演算

    利用matlab对f(x)在[0,1]进行等距插值,得到结果如下:

    源代码

    Runge.m:

    clear;clc; f=@(x)(1./(1+25.*x.^2)); N=[4 8 12]; X=linspace(-1,1,100); for i=1:3 n=N(i); x=linspace(-1,1,n+1); y=f(x); if i==1 Y1=interp_R(X,x,y); elseif i==2 Y2=interp_R(X,x,y); else Y3=interp_R(X,x,y); end end plot(x,y,'b-',X,Y1,'g:',X,Y2,'r-.',X,Y3,'y--'); legend('f(x)','n=4','n=8','n=12'); hold on; interp_R.m: function [Y] = interp_R(X,x,y) n=length(x); A=zeros(n,n); for ii=1:n temp=1; A(ii,1)=1; for jj=2:n temp=temp*x(ii); A(ii,jj)=temp; end end y=y'; Coeff=fliplr((A\y)'); Y=polyval(Coeff,X); end
    Processed: 0.013, SQL: 9