# 16.9 Differentiate

## Overview This function performs simple derivative calculations on a data set. The derivative at a given point is computed by taking the average of the slopes between the point and its two closest neighbors. Missing values are ignored.

For evenly-spaced X data, you can apply Savitzky-Golay smoothing. If the X data are not equally spaced, this method may not produce a reliable result.

##### To Use Differentiate Tool
1. Create a new worksheet with data.
2. Highlight the desired column.
3. Select Analysis: Mathematics:Differentiate from the Origin menu to open the differentiate dialog. The X-Function differentiate is called to perform the calculation.

## Dialog Options

Recalculate Controls recalculation of analysis results None Auto Manual For more information, see: Recalculating Analysis Results Specify the input XY range (curve). For help with range controls, see: Specifying Your Input Data Specify the derivative order. Specify smoothing method. Savitzky-Golay Smooth Use the Savitzky-Golay smoothing method. Polynomial Order This is available only when the smoothing is chosen. Set the polynomial order (1 to 9) for the Savitzky-Golay smoothing method. Points of Window This is available only when the smoothing is chosen. Set the window size used in the Savitzky-Golay smoothing. Specify the output range. For help with the range controls, see: Output Results Specify whether to plot the derivative curve.

## Algorithm

The derivative of a function is defined as: $f'(x)=\lim_{h \to 0} \frac{f(x+h)-f(x)}h$

While the $h\!$ is small enough, we can use a centered difference formula to approximate the derivative: $f'(x_i)\approx \frac{f(x_{i}+h)-f(x_{i}-h)}{2h}$

In practice, Origin treats discrete data by the transform of the centered difference formula, and calculates the derivative at point $Pi\!$ by taking the average of the slopes between the point and its two closest neighbors.

The derivative function applied to discrete data points can therefore be written: $f'(x_i)=\frac 12\left( \frac{y_{i+1}-y_i}{x_{i+1}-x_i}+\frac{y_i-y_{i-1}}{x_i-x_{i-1}}\right)$

When smooth option is chosen in differentiate, and X data is evenly spaced, Savitzky-Golay method will be used to calculate the derivatives.

First perform a polynomial regression on the data points in the moving window. The polynomial value at position x can be calculated as: $f(x)=a_nx^n+a_{n-1}x^{n-1}+a_{n-2}x^{n-2}+\ldots + a_1x + a_0$.

where n is the polynomial order, and $a_i, i=0...n$ are fitted coefficients.

And 1st order derivative at position x is: $f^{\prime }(x)=na_nx^{n-1}+(n-1)a_{n-1}x^{n-2}+...+a_1$.