How to find tangent line on the straight part of a graph?

조회 수: 13(최근 30일)
Din N
Din N 2021년 7월 7일
편집: John D'Errico 2021년 7월 8일
I need to plot 2 tangent lines and then find their intersection. The lines need to be found in the areas where the graph is 'straight", as you can see on the illustration.
This is what I have right now: (assume that tRange and yRange are just sets of data). I have a lot of data, so it would be impossible to share here. I would like some guidance on how to find the range where the graph is steady (straight) and how to do a tangent line at that part.
tRange=...
yRange=...
der=abs(diff(yRange)./diff(tRange)); % find derivative
[~, index]=find((der>=0) & (der<=0.1)) % find smallest difference
x1tangent=tRange(index); % x point for tangent line
y1tangent=yRange(index); % y point for tangent line
der_tan=der(index); % find the index of the smallest derivative
tang=(tRange-x1tangent)*der_tan+y1tangent; % find the tangent line
plot(tRange,tang)
I just can't have it working... I would appreciate at least some guidance. Thank you!
  댓글 수: 1
John D'Errico
John D'Errico 2021년 7월 7일
편집: John D'Errico 2021년 7월 8일
It is entirely possible to share your data. Save it as a .mat file. THen attach the .mat file to a comment. Easy peasy.
The point being, there are things we do not know, like how noisy is your data. What we do not know is if say, the x-coordinate moves by uniform increments, while y varies. We do not know if this is the common shape to expect, thus a roughly hyperbolic arc. Is a hyperbolic arc really the expected shape? I'm sure if I think about it, I could come up with other questions.
Given some data, I could see if a hyperbolic arc truly well approximates the data. Note that once you have a hyperbola, then deriving the tangents that you wish to see is trivial, as well as the point of intersection of those tangents.

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

답변(1개)

Star Strider
Star Strider 2021년 7월 7일
This is likely straightforward.
For specific help, the data will be necessary.
.

Community Treasure Hunt

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

Start Hunting!

Translated by