Find the amount of graph intersections
조회 수: 13 (최근 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!

