how to find intersection data between 2 function
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arif
am 25 Feb. 2024
Kommentiert: Walter Roberson
am 1 Mär. 2024
hi guys can u help me to find the data which is intersection between 2 line ?
this is my graph :

i have data for the blue-line graph. so that i have data for points A,B,C.
The red line is an extended linear line from point A to B.
The yellow line is an vertical line when X = C
How do i get the intersection data between red-line and yellow-line ? the code formula.
0 Kommentare
Akzeptierte Antwort
Sam Chak
am 25 Feb. 2024
Hi @Arif
The red line represents the extrapolation up to the vertical line
. The main concept here is to determine the equation of line
and subsequently calculate the y-coordinate of the intersection point.
A = [0, 0]; % point A
B = [0.05, -150]; % point B
C = 0.125; % vertical line, x = C
figure(1)
plot([A(1), B(1)], [A(2), B(2)]), hold on
xline(C, '--'), grid on
xlabel x, ylabel y
%% Find the line equation between A and B
f = fit([A(1), B(1)]', [A(2), B(2)]', 'poly1')
%% Intersection coordinate
xi = C; % x-coordinate of the intersection
yi = f.p1*xi + f.p2 % y-coordinate of the intersection
fprintf('The coordinate of the intersection is (%.4f, %.4f).', xi, yi);
figure(2)
xr = B(1):0.001:C;
yr = f.p1*xr + f.p2;
plot([A(1), B(1)], [A(2), B(2)], 'LineWidth', 2), hold on
plot(xr, yr, 'LineWidth', 2)
plot(A(1), A(2), 'o', 'LineWidth', 2, 'MarkerSize', 12)
plot(xi, yi, 'o', 'LineWidth', 2, 'MarkerSize', 12)
plot(B(1), B(2), 'o', 'LineWidth', 2, 'MarkerSize', 12), hold off
xline(C, '-', {'x = 0.125'}, 'color', '#123456'), grid on
xlabel x, ylabel y, xlim([0, 0.3])
0 Kommentare
Weitere Antworten (1)
Hassaan
am 25 Feb. 2024
Bearbeitet: Hassaan
am 25 Feb. 2024
@Arif A rough idea:
% Assuming you have the following coordinates
% A(xA, yA), B(xB, yB), and the x-coordinate of C (xC)
xA = % (your data for xA)
yA = % (your data for yA)
xB = % (your data for xB)
yB = % (your data for yB)
xC = % (your data for xC)
% Calculate the slope of the line AB (red line)
m = (yB - yA) / (xB - xA);
% Calculate the y-coordinate of the intersection point with the yellow line
yIntersect = m * (xC - xA) + yA;
% Display the intersection point
fprintf('The intersection occurs at (x, y) = (%.2f, %.2f)\n', xC, yIntersect);
Note:
- May need adjustment as per your requirement
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

