Compute the first derivative using a 4-point central difference [-2h,-h,h,2h].
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
procedure(func) | :: | f | ||||
complex(kind=wp), | intent(in) | :: | x | |||
real(kind=wp), | intent(in) | :: | h | |||
real(kind=wp), | intent(out) | :: | dfdx |
subroutine central_diff_4(f,x,h,dfdx) implicit none procedure(func) :: f complex(wp),intent(in) :: x real(wp),intent(in) :: h real(wp),intent(out) :: dfdx real(wp) :: h2 h2 = 2.0_wp * h dfdx = (f(x-h2) - 8.0_wp*f(x-h) + 8.0_wp*f(x+h) - f(x+h2)) / (12.0_wp*h) end subroutine central_diff_4