I have a data logger that is recording the temperature readings from thermocouples at a specific interval. This gives me data points that I can graph where the x-coordinate is time and the y-coordinate is temperature. For each set of data points that I graph, I can connect the points and make a line - usually curved. I need to find the derivative of each line and graph those as well. There is no known function that creates these curves, so I can't simply find the derivative of a function. All I have is a huge list of (x,y) coordinates. How do I take a derivative and graph it in this case?
Use a set of data points from a graph to find a derivative
46.8k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 3 best solutions below
On
There are several ways to get estimates of the derivative at the $i$-th point.
The simplest estimate is probably $(y_{i+1} - y_{i-1})/(x_{i+1} - x_{i-1})$. This is just the slope of the line between the $(i-1)$-th point and the the $(i+1)$-th point. You'll have to do something special at the first and last points, of course. For example, at the first point, use $(y_2 - y_1)/(x_2 - x_1)$, instead.
A slightly more sophisticated approach is to estimate the derivative at the $i$-th point by using the slope of the parabola passing through points $i-1$, $i$, and $i+1$. If this approach sounds attractive, and you need help figuring out the formula for this slope, feel free to ask again.
Edit: I just realized that the slope of the parabola is actually given by the formula above if the $x$-values are equally spaced. So, in this case, my two suggested solutions are actually one and the same.
Here are some graphs made using the first technique. The red curve shows function values, and the blue curve shows (estimated) derivative values:

On
Here is a simple way to implement the spline fitting and derivative taking in R:
x <- 0:100/10 # x = vector incrementing by 0.1
y <- sin(x)
f <- splinefun(x,y)
d_est <- f(x, deriv = 1)
## since we know d/dx sin(x) = cos(x), check:
## but note that it is not exactly equal b/c of different approaches
d_exact <- cos(x)
plot (x, y, type = 'l')
lines(x, d_est, col = 'blue')
lines(x, d_exact, col = 'red', lty = 2) # lty makes a dashed line
This generates a figure showing y in black, d(y) estimated with spline in blue and d(y) using the definition d/dx sin(x) = cos(x) in dashed red.

You can connect consecutive points with lines and assume that the derivative is the slope of these lines between these points. Of course, this makes the derivative noncontinuous (and not defined at the sample points).
A more elaborate idea would be to go for a spline interpolation, which would give a smoothe derivative