Slope is the change in the y value divided by the change in the x value. When dealing with numerical calculations, there are a number of different ways to perform this calculation.
The simplest way is a two point calculation. For each interval, calculate the change in y and divide by the change in x. For example, for the first calculation the slope is (y2-y1) / (x2-x1). Now the only remaining question is do you associate this slope value with x1 or x2.? I prefer to use the mid-point between x1 and x2, so I will calculate a new X value that correspond with this slope as X1_new = (X1+x2)/2.
Another method is to use the points that bound any given point, i.e. the one that preceeds it and the one that follows it. For example, the slope at x2 is calculated as x2_slope = (y3-y1)/(x3-x1). Notice how this straddles the #2 point, using point 1 and point 3 to perform the calculation. Both of these methods are shown in the plot. The red curve is the 2-point calculation, and the blue curve is the Mid-point (straddle) calculation.
These calculations are in the attached spreadsheet.
(I just noticed that the vertical axis in the slope plot is inverted, it goes from positive to negative - so don't let this throw you. The values are still right. The first three steps have positive slope because the value of the function is increasing, the later two steps have negative slope, because the function value is decreasing.)
Best Answer