MATLAB-如何从两条曲线中找到多个x和y交点

时间:2016-12-06 23:54:31

标签: matlab intersection

在下图中,两条曲线在3点相交。一个在左侧,一个在中间,一个在右侧。我需要找到三个交叉点的(x,y)坐标,但我很难弄清楚如何做到这一点。下面是我到目前为止的代码和情节:

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 个答案:

答案 0 :(得分: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)
相关问题