Find the amount of graph intersections
13 views (last 30 days)
Show older comments
r=(-2:0.03:5);
w=(-2:0.04:0);
g=cos((5.*r.^2+r-5)./(2.*r-3)+sqrt((r.^2+6)./(5-r)).^(1./3)+5.*r);
f=sin((w.^2+6.*w-2)./(w+3)+((w.^2+4.*w).^2)./(w+3));
hold on
yline(0,'Color','r','LineStyle','-.');
plot(r,g);
plot(w,f);
hold off
I have this code that creates 2 graphs with a yline for a reference. Of course,I can count the number of intersection between them manually,but is there a way to make this easier,taking in mind there exist more complicated graphs?
Edit:also,a possible way to find the number of intersections with yline?
0 Comments
Accepted Answer
Dyuman Joshi
on 22 Nov 2023
You can utilize this FEX Submission - https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections?s_tid=ta_fx_results
1 Comment
Dyuman Joshi
on 22 Nov 2023
r=(-2:0.03:5);
w=(-2:0.04:0);
g=cos((5.*r.^2+r-5)./(2.*r-3)+sqrt((r.^2+6)./(5-r)).^(1./3)+5.*r);
f=sin((w.^2+6.*w-2)./(w+3)+((w.^2+4.*w).^2)./(w+3));
%Value to plot the yline for
y0 = 0;
figure
hold on
yline(y0,'Color','r','LineStyle','-.');
plot(r,g);
plot(w,f);
Intersecting points of the 2 curves (r,g) and (w,f) -
P1 = InterX([r;g], [w;f]);
%Number of intersectin points
n1 = size(P1,2)
%Plot the intersecting points as red asteriks
plot(P1(1,:), P1(2,:), 'r*')
Intersecting points of the curve (r, g) with yline
P2 = InterX([r;g],[r;r.*0+y0]);
%Corresponding number of intersections
n2 = size(P2,2)
%Plot the intesrsecting points as black hollow circles
plot(P2(1,:), P2(2,:), 'ko')
hold off
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
