how can we find the intersect points of these two plots?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MOHD UWAIS
el 16 de Feb. de 2023
Respondida: Askic V
el 16 de Feb. de 2023
for y=-3:1:5;
G=[];
B=[];
for a=1:1:50
z=10;
x=a+y;
G=[G x];
b=z+30;
B=[B b];
end
B;
G;
a=1:1:50;
plot(a,G,'-')
hold on
plot(a,B,'-')
end
1 comentario
Rik
el 16 de Feb. de 2023
You have put the names of several people in the tags (which doesn't actually do anything), you didn't format or run your code (I just did that for you), and instead of 2 lines you have 10 lines.
So what actually is your question?
Respuesta aceptada
Oguz Kaan Hancioglu
el 16 de Feb. de 2023
Since B is constant it is easy to find the intersect point of lines using find command. Editted code listed below.
for y=-3:1:5;
G=[];
B=[];
for a=1:1:50
z=10;
x=a+y;
G=[G x];
b=z+30;
B=[B b];
end
B;
G;
a=1:1:50;
plot(a,G,'-')
hold on
plot(a,B,'-')
% find index
x = find(G == B(1));
% print intersect points
fprintf('intersect points = %.2f at %d, index number = %d\n',G(x),a(x),x);
% print intersect points on the plot
plot(a(x),G(x),'ro');
end
Best,
0 comentarios
Más respuestas (2)
Sulaymon Eshkabilov
el 16 de Feb. de 2023
Here is how to compute the intersect points of the plotted set of data points:
clearvars
close all
y=-3:1:5;
a=1:50;
for ii=1:numel(y)
G=[];
B=[];
for jj=1:numel(a)
z=10;
x=a(jj)+y(ii);
G=[G x];
b=z+30;
B=[B b];
end
plot(a,G,'-')
hold on
plot(a,B,'--')
Intersect = find(abs(B-G)==0);
ai = a(Intersect);
Gi = G(Intersect);
plot(ai, Gi, 'ro', 'MarkerFaceColor','y')
end
0 comentarios
Askic V
el 16 de Feb. de 2023
I think this small code snippet can be useful to you in future if you have a bit more general case:
x = 0:0.1:5;
y_val = 4*x-2;
intersect_points = [];
m = 2;
n = [1 2 3 4 5];
for i = n
y = m*x+i;
plot(x, y);
hold on
xisx = interp1(y-y_val, x, 0);
yisx = m*xisx+i;
plot(xisx, yisx,'o')
intersect_points = [intersect_points; xisx, yisx];
end
plot(x, y_val);
grid on
intersect_points
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!