📄 demo_runge.m
字号:
%% interpolation of Runge's function (1+x^2)^(-1)% on the interval [-5, 5]%clear;% Interval on which Runge's function is to be approximatedA = -5;B = 5;% evaluate Runge's function at zm = 1000;h = (B-A)/(m-1);z = (A:h:B);r = 1 ./(1+z.^2);n = input(' number of interpolation points n = ')% compute equidistant interpolation points% and function values to be interpolated h = (B-A)/(n-1); x = (A:h:B); f = 1 ./ (1+x.^2);% compute Newton's interpolating polynomial a = NewtIntPol( x, f, 0 );% evaluate Newton's interpolating polynomial at the % points z and plot it together with Runge's function. p = NewtIntPolEval( x, a, z );% plot the interpolating polynomial subplot(2,1,1) plot(z, p, 'r'); hold on % plot polynomial plot(z, r, 'g'); hold off % plot Runge's function title(['Interpolation of Runge''s Function at Equidistant Points (n=',... int2str(n),')'] )% compute Chebyshev interpolation points% and function values to be interpolated for i = 1:n x(i) = 0.5 * ( (A+B) + (B-A) * cos( (2*i-1)*pi/ (2*n) ) ); f(i) = 1 / (1+x(i)^2); end% compute Newton's interpolating polynomial a = NewtIntPol( x, f, 0 );% evaluate Newton's interpolating polynomial at the % points z and plot it together with Runge's function. p = NewtIntPolEval( x, a, z );% plot the interpolating polynomial subplot(2,1,2) plot(z, p, 'r'); hold on % plot polynomial plot(z, r, 'g'); hold off % plot Runge's function title(['Interpolation of Runge''s Function at Chebyshev Points (n=',... int2str(n),')'] )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -