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

2 次查看(过去 30 天)
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.
.

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by