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

10 views (last 30 days)
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.
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
I just can't have it working... I would appreciate at least some guidance. Thank you!
  1 Comment
John D'Errico
John D'Errico on 7 Jul 2021
Edited: John D'Errico on 8 Jul 2021
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.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 7 Jul 2021
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!