user4791235
user4791235

Reputation:

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

on the plot below, the two curves intersect at 3 points. One on the left side, one in the middle, and one on the right side. I need to find the (x,y) coordinates for the three intersection points, but I'm having a hard time figuring out how to do that. Below is my code so far and the plot:

Click here for plot

Here's my code:

% 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])

Upvotes: 0

Views: 164

Answers (1)

Yuval Atzmon
Yuval Atzmon

Reputation: 5945

Your code fails to execute (u1 is missing). But anyway, you can subtract lhs-rhs and then look for the results zero-crossing

i.e.

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)

Upvotes: 1

Related Questions