2016-12-06 82 views
0

找到多個x和y交點,如下圖所示,兩條曲線相交3點。一個在左邊,一個在中間,一個在右邊。我需要找到三個交點的(x,y)座標,但我很難弄清楚如何做到這一點。下面是到目前爲止我的代碼和劇情:MATLAB-如何從兩條曲線

Click here for plot

這裏是我的代碼:

% Define 

b1=3.5; 
b2=4.5; 
rho1=2.7; 
rho2=3.3; 
h=40; 
u2=(b2^2)*rho2; 


f1=.15; 
w1=2*pi*f1; 
cvec=3.5:.01:4.5; 
p2=1./cvec; 
lhs=tan(h*w1.*sqrt((1./b1.^2)-(p2.^2))); 
rhs=(u2.*sqrt((p2.^2)-(1./b2.^2)))./(u1.*sqrt((1./b1.^2)-(p2.^2))); 

plot(cvec,rhs,cvec,lhs) 
xlim([3.6 4.6]) 

回答

1

您的代碼執行失敗(u1缺失)。但無論如何,你可以減去LHS-RHS然後查找結果zero-crossing

zci = @(v) find(v(1:end-1).*circshift(v(2:end), [-1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector 
zx = zci(lhs-rhs); 
cross_points = cvec(zx)