Find the amount of graph intersections

조회 수: 13 (최근 30일)
Heorhii
Heorhii 2023년 11월 22일
댓글: 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));
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?

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 11월 22일
  댓글 수: 1
Dyuman Joshi
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)
n1 = 5
%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)
n2 = 26
%Plot the intesrsecting points as black hollow circles
plot(P2(1,:), P2(2,:), 'ko')
hold off

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by