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

MATLAB- How to find multiple x and y intersection points from two curves

在下图中,两条曲线相交于 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])

您的代码无法执行(缺少 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)