The central_diff function calculates a numeric gradient using second-order accurate difference formula for evenly or unevenly spaced coordinate data. It operates in a similar fashion to the MATLAB function, gradient, except that it permits only one independent variable, x, and correctly handles unevenly spaced values of the x-coordinate data. Accuracy is increased at the ends relative to the MATLAB gradient function, which uses only first-order forward or backward differences at the ends, by instead using second-order forward difference at the left end and second-order backward difference at the right end.
Robert Canfield (2021). central_diff.m (https://www.mathworks.com/matlabcentral/fileexchange/12-central_diff-m), MATLAB Central File Exchange. Retrieved .
I believe that line 127 should be:
Fx(end,:) = ( [1, -4, 3]/(2*H)*F(end-2:end,:) ).';
Fx(end,:) = ( [1, -4, 3]/(2*H)*F(m-2:m,:) ).';
Also, I believe that line 141 should be:
Fx(2:n-1,:) = ( F(3:n,:) - F(1:n-2,:) ) / (2*H);
Fx(2:n-1) = ( F(3:n,:) - F(1:n-2,:) ) / (2*H);
I think that line 98 should be (notice the "=" sign)
if n >= 3
to account for the case of length 3 vectors.
This is a very good and usefull add-on function. Thank you.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!