Find intersection of points in a graph
7 views (last 30 days)
Star Strider on 8 Jul 2022
It would help to have the actual data. Assuming that ‘y2’ is either a constant or a line defined as a function of the same independent variable values as ‘y1’, this is straightforward —
x = linspace(0, 9); % Independent Variable
y1 = 700*exp(-0.45*x); % Curve
y2 = 150; % Line
xint = interp1(y1-y2, x, 0) % X-Intercept (Interpolation)
plot(x, y1, [0 9], [1 1]*y2, xint, y2, 'sr')
legend('y_1', 'y_2', 'Intersection', 'Location','best')
text(xint, y2, sprintf(' \\leftarrow Intersection: X = %.3f',xint), 'Horiz','left', 'Vert','middle', 'Rotation',30)
See the documentation on the interp1 function for details.
If both lines are defined on different independent variable values, a separate intermediate interpolation to define them with respect to the same independent variable vector (using interp1) would be required first.
More Answers (2)
KSSV on 8 Jul 2022