central_diff_4 Subroutine

private subroutine central_diff_4(f, x, h, dfdx)

Compute the first derivative using a 4-point central difference [-2h,-h,h,2h].

Arguments

Type IntentOptional Attributes Name
procedure(func) :: f
complex(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: h
real(kind=wp), intent(out) :: dfdx

Called by

proc~~central_diff_4~~CalledByGraph proc~central_diff_4 complex_step_module::central_diff_4 proc~complex_step_test complex_step_module::complex_step_test proc~complex_step_test->proc~central_diff_4

Source Code

    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