Finite difference derivatives

Calculate derivatives based on finite difference formulation
214 Downloads
Updated 31 May 2020

View License

The code provides derivatives of two dimensional equi-spaced variables
using finite difference formulation.
Accuracy up to 8th order accurate for central and 6th order accurate for one sided (backward or forward).
Only and second derivatives can be calculated.
Derivatives at edge points are calculated at maximum possible accuracy
BCs have to enforced outside this code
var: Two dimensional variable
dim: Dimension along which the derivative is to be calculated
accuracy: Accuracy of finite difference formulation; 1,2..6 for one
sided, and 2,4,6,8 for central difference schemes.
order: Order of derivative: 1 for first derivative (e.g. du/dx) and 2
for second order derivative (e.g. d2u/dx2)
d_dim: spacing along the dimension specified in "dim"
type: a string specifying the type of formulation
'central' or 'forward' or 'backward'
% Example 1: dfd(u,1,3,1,0.01,'forward')
First derivative of u along 1st dimension. Forward,
one-sided, 3rd order accurate finite difference
formulation. A separation of 0.01 between
consecutive locations.
% Example 2: dfd(u,2,6,2,0.05); OR dfd(u,2,6,2,0.05,'central');
Second derivative of u along 2nd dimension. Central,
6th order accurate finite difference formulation.
A separation of 0.05 between consecutive locations.
% Example 3: dfd(u,2,6,2,0.01,'central-with-one-sided-edges');
Second derivative of u along 2nd dimension.
6th order accurate central finite difference formulation at the inner points.
6th order accurate one - sided finite difference formulation at the edge points.
A separation of 0.01 between consecutive locations.

Cite As

Tapish Agarwal (2024). Finite difference derivatives (https://www.mathworks.com/matlabcentral/fileexchange/76447-finite-difference-derivatives), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!

Version Published Release Notes
1.0.0