Find intersection of points in a graph
156 次查看(过去 30 天)
显示 更早的评论
Is there a way to find the intersection of two curves in the graph? If yes, can someone help me with the code
0 个评论
采纳的回答
Star Strider
2022-7-8
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)
figure
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)
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.
.
更多回答(2 个)
Hrusheekesh
2022-7-11
Hi chinmayraj,
You can also subtract the two curves and get the absolute difference, compare with the tolerance (ex: eps) for near values.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!