% 对龙格函数:
2(x)1(125)f x =+ 的三次样条插值. clear;
x0 = -1:0.1:1;
y0 = 1./(25*x0.^2);
x1 = linspace(-1,1,20);
y1 = interp1(x0,y0,x1,'spline');
plot(x0,y0,'b');
hold on
plot(x1,y1,'m');
title('三次样条插值','FontName',' Times New Roman ','FontSize',11); legend('龙格函数曲线','三次样条插值曲线',-2);
axis ([-1,1,0,1]);
xlabel('x 轴','FontName',' Times New Roman ','FontSize',11); ylabel('y 轴','FontName',' Times New Roman ','FontSize',11);
% 对龙格函数:
2(x)1(125)f x =+ 的三次多项式插值. clear;
x0 = [-1:0.01:1];
y0 = 1./(1+25*x0.^2);
x1 = linspace(-1,1,10);
y1 = interp1(x0,y0,x1,'cubic');
plot(x0,y0,'b');
hold on
plot(x1,y1,'m');
title('三次多项式','FontName','Times New Roman','FontSize',11); legend('龙格插值曲线','三次多项式插值曲线',-2);
axis ([-1,1,0,1]);
xlabel('x 轴','FontName',' Times New Roman ','FontSize',11); ylabel('y 轴','FontName',' Times New Roman ','FontSize',11);