插值线与插值曲线matlab的交集

时间:2016-12-16 09:04:30

标签: matlab interpolation intersection curve

我有一个straightline,其中包含以下数据

xinter=[1.13 1.36 1.62 1.81 2.00 2.30 2.61 2.83 3.05 3.39]
yinter=[0.10 0.25 0.40 0.50 0.60 0.75 0.90 1.00 1.10 1.25]

我希望找到与插值数据结果的交集 如下面的曲线

      a50=  [0.77 0.73 0.77 0.85 0.91 0.97 1.05 1.23 1.43 1.53 1.62 1.71 1.89 2.12 2.42];
a25=  [0.51 0.60 0.70 0.80 0.85 0.90 0.96 1.09 1.23 1.30 1.36 1.41 1.53 1.67];
vel25=[0.43 0.35 0.30 0.27 0.25 0.24 0.22 0.21 0.22 0.24 0.25 0.27 0.30 0.35];
vel50=[0.68 0.57 0.49 0.43 0.40 0.38 0.36 0.34 0.36 0.38 0.40 0.43 0.49 0.57 0.68 ];


% back up original data, just for final plot
bkp_a50 = a50 ; bkp_vel50 = vel50 ;

% make second x vector monotonic
istart = find( diff(a50)>0 , 1 , 'first') ;
a50(1:istart-1) = [] ;
vel50(1:istart-1) = [] ;

% prepare a 3rd dimension vector (from 25 to 50)
T = [repmat(25,size(a25)) ; repmat(40,size(a50)) ] ;
% merge all observations together
A = [  a25 ;   a50] ;
V = [vel25 ; vel50] ;

% find the minimum domain on which data can be interpolated
% (anything outside of that will return NaN)
Astart = max( [min(a25) min(a50)] ) ;
Astop  = min( [max(a25) max(a50)] ) ;

% use the function 'griddata'
[TI,AI] = meshgrid( 25:40 , linspace(Astart,Astop,10)  ) ; 
VI = griddata(T,A,V,TI,AI) ;

% plot all the intermediate curves
%plot(AI,VI)
hold on
% the original curves
%plot(a25,vel25,'--k','linewidth',2)
%plot(bkp_a50,bkp_vel50,'--k','linewidth',2)
% Highlight the curve at T = 30 ;
c30 = find( TI(1,:) == 40 ) ;
plot(AI(:,c30),VI(:,c30),'--r','linewidth',2)

xinter=[1.13 1.36 1.62 1.81 2.00 2.30 2.61 2.83 3.05 3.39]
yinter=[0.10 0.25 0.40 0.50 0.60 0.75 0.90 1.00 1.10 1.25]


x1inter=(AI(:,c30))';
y1inter=(VI(:,c30))';


yy2 = interp1(xinter, yinter, x1inter,'spline')


plot(xinter,yinter, '--k','linewidth',2)

 idx = find((y1inter - yy2) < eps, 1); %// Index of coordinate in array
 px = x1inter(idx)
py = y1inter(idx)
plot(px, py, 'ro', 'MarkerSize', 18)

但修改x1inter

时结果出错

1 个答案:

答案 0 :(得分:-1)

您可以使用分段多项式曲线拟合和fzero函数来查找交点:

pp1 = pchip(xinter,yinter);         % Curve 1
pp2 = pchip(AI(:,c30),VI(:,c30));   % Curve 2
fun = @(x) ppval(pp1,x) - ppval(pp2,x); % Curve to evaluate
xzero = fzero(fun,mean(xinter)) % intersection x value
yzero = ppval(pp1,xzero)
plot(xzero, yzero, 'bo', 'MarkerSize', 18)