Find the amount of graph intersections
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dyuman Joshi
2023-11-22
You can utilize this FEX Submission - https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections?s_tid=ta_fx_results
1 个评论
Dyuman Joshi
2023-11-22
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

