% 三次样条插值对机翼形状进行拟合
% 2022/12/5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=[0.52,3.1,8.0,17.95,28.65,39.62,50.65,78,104.6,156.6,208.6,260.7,...
312.5,364.4,416.3,468,494,507,520]; % 样本点x轴投影值
y=[5.28794,9.4,13.84,20.2,24.9,28.44,31.1,35,36.5,36.6,34.6,31.0,...
26.34,20.9,14.8,7.8,3.7,1.5,0.2]; % 样本点y轴投影值
x1=[2,4,6,12,16,30,60,110,180,280,400,515]; % 在左侧x轴值中估计y轴值
diff_y0=1.86548;
diff_yn=-0.046115;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 计算三次样条插值
t=0.52:0.1:520; % 设置步长
S=interp1(x,y,t,'spline'); % 进行三次样条插值
plot(t,S,'-','Linewidth',0.5); % 绘制三次样条插值图像
hold on
plot(x,y,'or','Linewidth',0.5, 'MarkerSize',6); % 绘制样本点
hold on
TestS = 1:1:12;
for i=1:12
TestS(i)=spline(x,y,x1(i));%对S(i)赋值
end
disp(TestS)
plot(x1,TestS,'v','Linewidth',0.5,'MarkerSize',6,'MarkerEdgeColor',[0.3010 0.7 0.7]); % 绘制估计点
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 设置画布风格和基本信息
title('对机翼形状插值拟合具有二阶光滑度函数'); % 图像的标题
xlabel('X'); ylabel('Y'); % 命名x,y轴
set(gca, 'XTick', 0:520/26:520); set(gca, 'YTick', 0:50/5:50); % 步长
legend('三次样条插值函数图像','样本点','估计点') % 对图标进行标注
grid on; axis equal; % 使x轴y轴比例一致
hold off