Increase the accuracy of vector differentiation

4 views (last 30 days)
Hello,
I am suppose to do data analysis, I should differentiate vectors and I do that using diff function in Matlab, I got approxmated results as figure shows. my question is how to find the differentation without rounding numbers, I suppose to have values as in the second picture.
  1 Comment
Chandler Hall
Chandler Hall on 11 Nov 2022
The diff function does not calculate derivatives, but rather finite differences. So if g = diff(f) then g(x) = f(x+1) - f(x).
This is equivalent to the slope of the secant line between these points on the curve, which will only equal the slope of the tangent line as the distance between samples points goes to zero.
To calculate instantaneous derivatives from a finite series, you would need to fit some curve to the data which you could then analytically differentiate.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 11 Nov 2022
The best way to calculate the numerical derivative is with the gradient function.
Since differentiation amplifies noise, filtering the data first, perhaps with the Savitzky-Golay filter sgolayfilt function, may be necessary.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!