How to find tangent line on the straight part of a graph?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
John D'Errico
el 7 de Jul. de 2021
Editada: John D'Errico
el 8 de Jul. de 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.
Respuestas (1)
Star Strider
el 7 de Jul. de 2021
This is likely straightforward.
See for example: How to draw tangent line at infleciton point? and How to draw a tangent line on a curve.
For specific help, the data will be necessary.
.
0 comentarios
Ver también
Categorías
Más información sobre Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!