MATLAB:在样条曲线端点上强加导数

时间:2016-05-08 11:35:20

标签: matlab spline

我在MATLAB中编写一个代码,用于扩展翼型的升力和阻力系数的可用数据范围(一些系数取决于翼型的迎角)超出某些上限aoa_h且低于某些下限aoa_l

具体来说,我将一些数据[aoa_array Cl_array][aoa_array Cd_array]与那些C_l和C_d函数连接起来:

C_l =A_1 sin(2*aoa) + A_2 cos^2(aoa) / sin(aoa)
C_d =B_1 sin^2(aoa)+B_2 cos(aoa)

对于数据,我使用MATLAB spline函数来确保平滑。我还想在数据的上限和下限强加样条导数,使其与我连接的函数相同。我计算了这些 derivatives

dC_l/dalpha=A_1 2(1-2sin^2(alpha))-A_2 cos(alpha)(1+1/sin^2(alpha))
dC_d/dalpha =B_1 2sin(alpha) cos(alpha)-B_2 sin(alpha)

以下是我使用的代码:

    function [Cl,Cd]=LD_simple(aoa,aoa_array,Cl_array,Cd_array)
    % Preallocation
    l=length(aoa);
    Cl=zeros(l,1);
    Cd=zeros(l,1);

    % Highest data of aoa, Cl and Cd
    Cl_high=Cl_array(end);
    Cd_high=Cd_array(end);
    aoa_h=aoa_array(end);
    sinaoa_h=sind(aoa_h);
    cosaoa_h=cosd(aoa_h);

    % Lowest data of aoa, Cl and Cd
    Cl_low=Cl_array(1);
    Cd_low=Cd_array(1);
    aoa_l=aoa_array(1);
    sinaoa_l=sind(aoa_l);
    cosaoa_l=cosd(aoa_l);

    % Coefficients for Viterna and Corrigan approximation
    Cd_max=1.11+3*0.18; % empiric relation
    A1=Cd_max/2;
    B1=Cd_max;

    % Coefficients that are tweaked for the function to match the data at endpoints
    A2_h=(Cl_high-Cd_max*sinaoa_h*cosaoa_h)*sinaoa_h/cosaoa_h^2;
    B2_h=(Cd_high-Cd_max*sinaoa_h^2)/cosaoa_h;

    A2_l=(Cl_low-Cd_max*sinaoa_l*cosaoa_l)*sinaoa_l/cosaoa_l^2;
    B2_l=(Cd_low-Cd_max*sinaoa_l^2)/cosaoa_l;

    % Index for splines and extrapolation
    index1=aoa<=max(aoa_array_t) & aoa>=min(aoa_array_t); % aoa in data range
    index2=aoa>max(aoa_array_t); % aoa higher than data range
    index3=aoa<min(aoa_array_t); % aoa lower than data range

    % Endpoints derivatives
    dCl_h=A1*2*(1-2*sinaoa_h^2)+A2_h*(-cosaoa_h-cosaoa_h/sinaoa_h^2);
    dCl_l=A1*2*(1-2*sinaoa_l^2)+A2_l*(-cosaoa_l-cosaoa_l/sinaoa_l^2);
    dCd_h=2*B1*sinaoa_h*cosaoa_h-B2_h*sinaoa_h;
    dCd_l=2*B1*sinaoa_l*cosaoa_l-B2_l*sinaoa_l;

    % Spline interpolation and Viterna&Corrigan extrapolation
    Cl(index1)=spline(aoa_array,[dCl_l; Cl_array; dCl_h], aoa(index1));
    Cd(index1)=spline(aoa_array,[dCd_l; Cd_array; dCd_h], aoa(index1));
    Cl(index2)=A1*sind(2*aoa(index2))+A2_h*(cosd(aoa(index2))).^2./sind(aoa(index2));
    Cd(index2)=B1*sind(aoa(index2)).^2+B2_h*cosd(aoa(index2));
    Cl(index3)=A1*sind(2*aoa(index3))+A2_l*cosd(aoa(index3)).^2./sind(aoa(index3));
    Cd(index3)=B1*sind(aoa(index3)).^2+B2_l*cosd(aoa(index3));
end

不幸的是它不起作用: plot

有人知道会出现什么问题吗?

0 个答案:

没有答案