MATLAB: How to perform differentiation on data samples

differentiationMATLABnumericalsymbolic

How do I perform differentiation on data samples using MATLAB?

Best Answer

You can use the DIFF function to perform the differentiation.
PLEASE NOTE: DIFF is an overloaded function that behaves differently with different types of input.
You can use the DIFF function with MATLAB to obtain the difference. For example: If your data sample X is:
X= [X1 X2 X3 X4 X5 X6.... Xn]
then
diff(X)
will result in
[(X2-X1) (X3-X2) (X4-X3) .... (Xn-Xn-1)].
More information on DIFF can be found by typing the following at the MATLAB command prompt:
help diff
However, if you need to find the differentiation of the type d/dx, then you will need the DIFF function with the Symbolic Math Toolbox. The DIFF function in the Symbolic Math Toolbox differentiates a symbolic expression S with respect to its free variable. More information on this DIFF can be found by typing the following at the MATLAB command prompt:
help sym/diff
.