We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

How to calculate the tangent of a curved line in LibreOffice Calc

asked 2021-03-03 14:58:30 +0200

mab gravatar image

I already plotted my graph as shown below

image description

How do calculate the Tangent at each point, e.g at (0.75,0.4)

Like how can I draw that straight line that touches the curve at only that point without crossing the curve

edit retag flag offensive close merge delete


How should anybody know without any idea of the functional relation of (x,y) values.

Opaque gravatar imageOpaque ( 2021-03-03 15:58:57 +0200 )edit

@Opaque you can calculate local slope and shift the tangent line using local value - see my answer. That'll work as long as the function is not doing anything crazy.

Przemo gravatar imagePrzemo ( 2021-03-03 16:16:29 +0200 )edit

That'll work as long as the function is not doing anything crazy.

And this is putting an assumption into functional relation of (x,y) values and exactly what is meant by my comment (as far as I understand your solution, you linearize between 2 data points)

Opaque gravatar imageOpaque ( 2021-03-03 16:24:50 +0200 )edit

You can try to fit a quadratic curve ax²+bx+c passing through 3 points (xi-1, yi-1), (xi, yi) and (xi+1, yi+1) where you are interested in the tangent at (xi, yi). Solve for a and b and draw the line passing by (xi, yi).

You may also attempt to approximate the slope between point i-1 and i+1 and apply this to a line passing by i, assuming that the "continuous" curve is sufficiently "regular" (no noise nor sudden "jump").

ajlittoz gravatar imageajlittoz ( 2021-03-03 16:49:46 +0200 )edit

You may want to check function LINEST() for a polynomial regression (e.g of degree 2) and which would provide all parameters required for your orig question calculate the Tangent at each point (i.e. getting a function which allows calculation of the tangent at each point from 3 values (in case of degree 2 polynomial). However: This also puts an assumption/regression type/approximation into the data.

See the following sample file: C:\fakepath\LINEST-Degree2-Polynomial-Tangent.ods

Opaque gravatar imageOpaque ( 2021-03-03 17:09:41 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2021-03-03 16:15:16 +0200

Przemo gravatar image

I''m not sure if there is a LO solution to this. A math solution attached. Tangent line at 0.7, but it easy to adjust by dragging cells.

image description


edit flag offensive delete link more


Thanks for being of help, I would have upvoted this but I'm a new user here (not enough points). I should accept the answer as this is exactly what I wanted to do BUT i don't understand how you get this to work - Are 1.3 and -0.42 constants? What if I wanted for another points? Please help explain how you get this to work. Like how to generate a & b for other points

mab gravatar imagemab ( 2021-03-03 18:41:02 +0200 )edit

Please don't get me wrong, but this sample solution perfectly demonstrates my comment about idea of functional relation of (x,y) values. The solution uses function f(x)=x2 sample data and evaluates by linearization a slope of 1.3 at data point 0.7 while the mathematical first derivative analytically yields f'(x)=2*x=1.4. If we had an idea of something like data have a polynomial relation then using LINEST() would yield 1.4 almost exactly.

Opaque gravatar imageOpaque ( 2021-03-04 00:21:31 +0200 )edit

@mab a and b are constants describing tangent line at the desired point.They are calculated, so you can drag the calls if you want to use e.g. 0.3 instead of 0.7 @Opaque I think that using LINEST and 2 extrapolated points (one extrapolated from the desired point and the previous point and another from the desired point and the next point) we could get a cleaner solution than. I need to test that.

Przemo gravatar imagePrzemo ( 2021-03-04 09:23:20 +0200 )edit


Check this sample file, which is an adaption of the file from my comment above to your sample data: C:\fakepath\Parabel-LINEST-Degree2-Polynomial-Tangent.ods

...think that using LINEST and 2 extrapolated points

Just to avoid a misunderstanding based on the name of the LINEST() function: It is not limited to regression analysis of linear functions. The name derives from the method used to perform regression analysis. If you wonder, why there is a column X2 in my sample file: That's the method of LINEST() performing a linearization of a polynomial; e.g. if you want a 4-degree polynomial, you would need 2 more columns X3 (column D) and X4 (column E), y-values shift to column F and a {=LINEST(F2:F10;B2:E10;1)}

Opaque gravatar imageOpaque ( 2021-03-04 09:59:56 +0200 )edit

answered 2021-03-03 16:48:13 +0200

erAck gravatar image

As a general approach you need to calculate the slope of your curve at a given point and calculate two points of the derivative function to draw a line. If your curve follows some differentiable function y=f(x) then you can try a tangent line calculator to determine the parameters of a local linearisation. If your curve does not follow a f(x) but consists of more or less arbitrary x,y pairs then you're better off by using two nearby points to calculate a local slope as in the example provided by Przemo. (or even zooming in and drawing a line manually).

See also a discussion of tangent line approximation.

edit flag offensive delete link more


Since the line is curved, I though the only way to get the slope at that point is through the Tangent? Thanks for the link and being of help. I would love to upvote this answer but I don't have enough points yet. Przemo's answer above looks good but I don't understand how he came about his solution, I pray he updates his answer. Thanks once again.

mab gravatar imagemab ( 2021-03-03 18:53:13 +0200 )edit

The slope of a tangent line at a given point of a curve is the same as the slope of the curve locally near that point (dy/dx). The slope of a curve of function f(x) at a given point (a,f(a)) is the derivative function f'(x) for (a,f'(a)). Hence iff you have a function y=f(x) that is differentiable at x=a it is the best way to calculate the tangent line, with y=f(x) and m=(a,f'(a))=dy/dx just find a second point y2 on the line for another x, or preferably the intersection with y=0 and other points to draw a beautiful line ;-) as Opaque's sample document in the other comment nicely illustrates.

erAck gravatar imageerAck ( 2021-03-04 22:02:28 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2021-03-03 14:58:30 +0200

Seen: 81 times

Last updated: Mar 03