%% Run in this .mFile
%% f(x)=sin(x)
x = -5:5;
y = sin(x);
p = NewtonInterpolate(x,y);% get interpolation polynomial of sin(x)
x = -5:0.1:5; % in order to get a smooth figure, the step value is 0.1
y = p(x);
figure(1);
plot(x,y,'r','LineWidth',2);hold on % interpolation polynomial
plot(x,sin(x),'--b','LineWidth',2); % original function
title('f(x)=sin(x)');
legend('Original Function','NewTon Interpolate Function');
grid on
%% f(x)=1/(1+x*x)
x = -5:5;
y = 1./(1+x.*x);
p = NewtonInterpolate(x,y); % get interpolation polynomial of 1/(1+x*x)
x = -5:0.1:5;
y = p(x);
figure(2);
plot(x,y,'r','LineWidth',2);hold on % interpolation polynomial
plot(x,1./(1+x.*x),'--b','LineWidth',2); % original function
title('f(x)=1/(1+x*x)');
legend('Original Function','NewTon Interpolate Function');
grid on
newton interpolation (牛顿多项式插值法)
需积分: 36 118 浏览量
2018-12-06
10:46:53
上传
评论
收藏 1KB ZIP 举报
贤愚翻身
- 粉丝: 0
- 资源: 8