필터 지우기
필터 지우기

Find intersection of points in a graph

조회 수: 48 (최근 30일)
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa 2022년 7월 8일
답변: Hrusheekesh 2022년 7월 11일
Is there a way to find the intersection of two curves in the graph? If yes, can someone help me with the code

채택된 답변

Star Strider
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)
xint = 3.4236
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)
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.
.
  댓글 수: 2
Chinmayraj Doddarajappa
Chinmayraj Doddarajappa 2022년 7월 8일
Thank you
Star Strider
Star Strider 2022년 7월 8일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KSSV
KSSV 2022년 7월 8일

Hrusheekesh
Hrusheekesh 2022년 7월 11일
Hi chinmayraj,
You can refer to this page to find the intersection of two curves.
You can also subtract the two curves and get the absolute difference, compare with the tolerance (ex: eps) for near values.

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by