# Calculating The Slope Of A Line At A Specific Point

Let's say I have an "S" shaped curve made up of 50 points. I am only given the data points, and there is no simple or obvious equation for each point on the curve.

So given only the data points, how would I be able to calculate the slope of the curve at a particular data point?

-

Estimate the tangent by taking the secants you can compute; you the tangent will lie somewhere between the two.

That is: you cannot compute the slope exactly, but you can estimate it from the information you have.

You have immediately preceding and immediately succeeding points, $t_{i-1}$ and $t_{i+1}$, as well as value $f(t_{i-1})$, $f(t_i)$, and $f(t_{i+1})$. The secant between $(t_{i-1},f(t_{i-1}))$, and $(t_i,f(t_i))$ has a certain slope $L_1$; the secant between $(t_i,f(t_i))$ and $(t_{i+1},f(t_{i+1}))$ has a certain slope $L_2$. Unless the graph is very nasty, the tangent at $(t_i,f(t_i))$ should have a slope that is somewhere between $L_1$ and $L_2$.

-

The simplest is just to take one of the neighboring points and find the slope of the line through those two. This approach is sensitive to measurement error in the points, particularly if they are measured at x values that are close together. Another approach is to fit some functional form (like an arctangent or logistic function is your data is S shaped) through the data points. This is smoothing, so will be less sensitive to measurement error (particularly if it has fewer parameters than you have measurements), but is sensitive to modeling error. There is a discussion in chapters 3 and 15 of Numerical Recipes

-
Once the spline is defined, for each segment with curve coordinates ($x(\alpha)$,$y(\alpha)$) the slope is $$s=\frac{\mathrm{d}y/\mathrm{d}\alpha}{\mathrm{d}x/\mathrm{d}\alpha}$$ evaluated at the desired location parameter $\alpha=0\ldots1$.