Find the amount of graph intersections

17 visualizaciones (últimos 30 días)
Heorhii
Heorhii el 22 de Nov. de 2023
Comentada: Dyuman Joshi el 22 de Nov. de 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));
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?

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 22 de Nov. de 2023
  1 comentario
Dyuman Joshi
Dyuman Joshi el 22 de Nov. de 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)
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by