Processing math: 100%

get_numerical_derivative Subroutine

public subroutine get_numerical_derivative(x, y, dy, dxtol)

Calculates the numerical derivative of a given array. A sixth-order accurate central difference stencil is used to calculate the derivative. Near the edges a sixth-order accurate forward and backward difference stencil is used for the left and right boundary, respectively. It is assumed that the x values are all equally spaced. If this is not the case, a polynomial interpolation on a uniform grid can be done and that one can be differentiated instead. The stencils are as follows:

  • 6th order central differences: dyi=yi3+9yi245yi1+45yi+19yi+2+yi+360dx
  • 6th order forward differences: dyi=147yi+360yi+1450yi+2+400yi+3225yi+4+72yi+510yi+660dx
  • 6th order backward differences: dyi=10yi672yi5+225yi4400yi3+450yi2360yi1+147yi60dx

Arguments

TypeIntentOptionalAttributesName
real(kind=dp), intent(in) :: x(:)

x-values against which to differentiate

real(kind=dp), intent(in) :: y(:)

array of y-values, assuming y(x) relation

real(kind=dp), intent(out) :: dy(size(y))

derivative of y with respect to x, same size as input arrays

real(kind=dp), intent(in), optional :: dxtol

optional tolerance for equally spaced arrays


Contents

None