如何插入随机非单调递增数据

How to interpolate random non monotonic increasing data

所以我正在写我的论文,我需要计算机翼的几何特征。

为此,我需要插入机翼的水平和垂直坐标。这用于自动计算来自随机机翼几何文件的几何特征的工具。

有时机翼的 Y 值是非单调的。因此,interp1 命令会出错,因为 Y 向量中的某些值是重复的。

因此,我的问题是:如何在 Matlab 中自动识别并随后插入非单调递增数据。

这是一个示例数据集:

 0.999974    0.002176
 0.994846    0.002555
 0.984945    0.003283
 0.973279    0.004131
 0.960914    0.005022
 0.948350    0.005919
 0.935739    0.006810
 0.923111    0.007691
 0.910478    0.008564
 0.897850    0.009428
 0.885229    0.010282
 0.872617    0.011125
 0.860009    0.011960
 0.847406    0.012783
 0.834807    0.013598
 0.822210    0.014402
 0.809614    0.015199
 0.797021    0.015985
 0.784426    0.016764
 0.771830    0.017536
 0.759236    0.018297
 0.746639    0.019053
 0.734038    0.019797
 0.721440    0.020531
 0.708839    0.021256
 0.696240    0.021971
 0.683641    0.022674
 0.671048    0.023367
 0.658455    0.024048
 0.645865    0.024721
 0.633280    0.025378
 0.620699    0.026029
 0.608123    0.026670
 0.595552    0.027299
 0.582988    0.027919
 0.570436    0.028523
 0.557889    0.029115
 0.545349    0.029697
 0.532818    0.030265
 0.520296    0.030820
 0.507781    0.031365
 0.495276    0.031894
 0.482780    0.032414
 0.470292    0.032920
 0.457812    0.033415
 0.445340    0.033898
 0.432874    0.034369
 0.420416    0.034829
 0.407964    0.035275
 0.395519    0.035708
 0.383083    0.036126
 0.370651    0.036530
 0.358228    0.036916
 0.345814    0.037284
 0.333403    0.037629
 0.320995    0.037950
 0.308592    0.038244
 0.296191    0.038506
 0.283793    0.038733
 0.271398    0.038920
 0.259004    0.039061
 0.246612    0.039153
 0.234221    0.039188
 0.221833    0.039162
 0.209446    0.039064
 0.197067    0.038889
 0.184693    0.038628
 0.172330    0.038271
 0.159986    0.037809
 0.147685    0.037231
 0.135454    0.036526
 0.123360    0.035684
 0.111394    0.034690
 0.099596    0.033528
 0.088011    0.032181
 0.076685    0.030635
 0.065663    0.028864
 0.055015    0.026849
 0.044865    0.024579
 0.035426    0.022076
 0.027030    0.019427
 0.019970    0.016771
 0.014377    0.014268
 0.010159    0.012029
 0.007009    0.010051
 0.004650    0.008292
 0.002879    0.006696
 0.001578    0.005207
 0.000698    0.003785
 0.000198    0.002434
 0.000000    0.001190
 0.000000    0.000000
 0.000258   -0.001992
 0.000832   -0.003348
 0.001858   -0.004711
 0.003426   -0.005982
 0.005568   -0.007173
 0.008409   -0.008303
 0.012185   -0.009379
 0.017243   -0.010404
 0.023929   -0.011326
 0.032338   -0.012056
 0.042155   -0.012532
 0.052898   -0.012742
 0.064198   -0.012720
 0.075846   -0.012533
 0.087736   -0.012223
 0.099803   -0.011837
 0.111997   -0.011398
 0.124285   -0.010925
 0.136634   -0.010429
 0.149040   -0.009918
 0.161493   -0.009400
 0.173985   -0.008878
 0.186517   -0.008359
 0.199087   -0.007845
 0.211686   -0.007340
 0.224315   -0.006846
 0.236968   -0.006364
 0.249641   -0.005898
 0.262329   -0.005451
 0.275030   -0.005022
 0.287738   -0.004615
 0.300450   -0.004231
 0.313158   -0.003870
 0.325864   -0.003534
 0.338565   -0.003224
 0.351261   -0.002939
 0.363955   -0.002680
 0.376646   -0.002447
 0.389333   -0.002239
 0.402018   -0.002057
 0.414702   -0.001899
 0.427381   -0.001766
 0.440057   -0.001656
 0.452730   -0.001566
 0.465409   -0.001496
 0.478092   -0.001443
 0.490780   -0.001407
 0.503470   -0.001381
 0.516157   -0.001369
 0.528844   -0.001364
 0.541527   -0.001368
 0.554213   -0.001376
 0.566894   -0.001386
 0.579575   -0.001398
 0.592254   -0.001410
 0.604934   -0.001424
 0.617614   -0.001434
 0.630291   -0.001437
 0.642967   -0.001443
 0.655644   -0.001442
 0.668323   -0.001439
 0.681003   -0.001437
 0.693683   -0.001440
 0.706365   -0.001442
 0.719048   -0.001444
 0.731731   -0.001446
 0.744416   -0.001443
 0.757102   -0.001445
 0.769790   -0.001444
 0.782480   -0.001445
 0.795173   -0.001446
 0.807870   -0.001446
 0.820569   -0.001446
 0.833273   -0.001446
 0.845984   -0.001448
 0.858698   -0.001448
 0.871422   -0.001451
 0.884148   -0.001448
 0.896868   -0.001446
 0.909585   -0.001443
 0.922302   -0.001445
 0.935019   -0.001446
 0.947730   -0.001446
 0.960405   -0.001439
 0.972917   -0.001437
 0.984788   -0.001441
 0.994843   -0.001441
 1.000019   -0.001441

第一列是 X,第二列是 Y。注意 Y 的最后一个值是如何重复的。

也许有人可以为我提供一段代码来做到这一点?或者也欢迎任何建议。

记住我需要自动执行此过程。

非常感谢您付出的时间和精力!

要插入任何函数,必须定义一个函数。当您定义 y=f(x) 时,对于 y 的两个不同值,您不能有相同的 x,因为那样我们就不是在谈论函数。在您的示例数据中,xy 都不是单调的,因此无论如何您将其切片,对于相同的 "x",您将有两个(或更多)"y"。如果你想插值,你需要把它分成两个单独的问题,top/bottom 并为 interp1/2/n 定义适当的函数来处理,例如,在 x==0 处水平切片。在任何情况下,您都必须提供额外的信息,而不仅仅是 xy,例如:x=0.5y 在最上面。

另一方面,如果您只想在数组中的每个 xy 之间插入一些值,您可以使用有限差分来做到这一点:

%// transform your original xy into 3d array where x is in first slice and y in second
xy = permute(xy(85:95,:), [3,1,2]); %// 85:95 is near x=0 in your data

%// lets say you want to insert three additional points along each line between every two points on given airfoil
h = [0, 0.25, 0.5, 0.75].'; %// steps along each line - column vector

%// every interpolated h along the way between f(x(n)) and f(x(n+1))  can
%// be defined as: f(x(n) + h) = f(x(n)) + h*( f(x(n+1)) - f(x(n)) )
%// this is first order finite differences approximation in 1D. 2D is very
%// similar only with gradient (this should be common knowledge, look it up)

%// from here it's just fancy matrix play

%// 2D gradient of xy curve
gradxy = diff(xy, 1, 2); %// diff xy, first order, along the 2nd dimension, where x and y now run
h_times_gradxy = bsxfun(@times, h, gradxy); %// gradient times step size
xy_in_3d_array = bsxfun(@plus, xy(:,1:end-1,:), h_times_gradxy); %// addition of "f(x)" and there we have it, the new x and y for every step h
[x,y] = deal(xy_in_3d_array(:,:,1), xy_in_3d_array(:,:,2)); %// extract x and y from 3d matrix
xy_interp = [x(:), y(:)]; %// use Matlab's linear indexing to flatten x and y into columns

%// plot to check results
figure; ax = newplot; hold on;
plot(ax, xy(:,:,1), xy(:,:,2),'o-');
plot(ax, xy_interp(:,1), xy_interp(:,2),'+')
legend('Original','Interpolated',0);
axis tight;
grid;

%// The End

这些是结果,在 x=0 附近为清楚起见:

希望对您有所帮助。 干杯。

如果您不知道定义箔片轮廓的确切函数,则有一种快速而肮脏的方法。将您的数据分成 2 组,顶部平面和底部平面,因此 'x' 数据为 monotonic increasing

首先我在变量A中导入了你的数据table,然后:

%// just reorganise your input in individual vectors. (this is optional but
%// if you do not do it you'll have to adjust the code below)
x = A(:,1) ;    
y = A(:,2) ;

ipos = y >  0 ;                             %// indices of the top plane
ineg = y <= 0 ;                             %// indices of the bottom plane

xi = linspace(0,1,500) ;                    %// new Xi for interpolation

ypos = interp1( x(ipos) , y(ipos) , xi ) ;  %// re-interp the top plane
yneg = interp1( x(ineg) , y(ineg) , xi ) ;  %// re-interp the bottom plane

y_new = [fliplr(yneg) ypos] ;               %// stiches the two half data set together
x_new = [fliplr(xi) xi] ;

%% // display
figure
plot(x,y,'o')
hold on
plot(x_new,y_new,'.r')
axis equal

正如上面所说,它又快又脏。从细节图中可以看出,这样可以在轮廓接近水平方向的区域大大提高 x 分辨率,但是在箔的绞索处会降低分辨率轮廓接近垂直方向。


如果是acceptable那么你就大功告成了。如果你真的需要鼻子的分辨率,你可以像上面那样在 x 上插值,但是在绞索附近做一个非常好的 x 网格(而不是我提供的常规 x 网格例如)。
如果您将上面的 xi 定义替换为:

xi = [linspace(0,0.01,50) linspace(0.01,1,500)] ;

您在鼻子附近得到以下信息:

根据您的需要进行调整。