Calculates the derivative of a scalar-valued function w.r.t. a vector-valued variable using the forward finite difference method.
Type | Intent | Optional | Attributes | Name | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
private impure function f(z) result(fz)Arguments
Return Value real(kind=rk)scalar function |
||||||||||||||||||||
real(kind=rk), | intent(in), | dimension(:) | :: | x |
vector variable |
|||||||||||||||
real(kind=rk), | intent(in) | :: | h |
perturbation for finite difference methods |
derivative of w.r.t.
impure function finite_difference_forward_T0_T1(f, x, h) result(dfdx) real(rk), dimension(:), intent(in) :: x !! vector variable real(rk), intent(in) :: h !! perturbation for finite difference methods real(rk), dimension(size(x)) :: dfdx !! derivative of \(f\) w.r.t. \(\mathbf{x}\) real(rk), dimension(size(x)) :: temp_x !! temporary vector variable integer :: i !! loop index interface !! scalar-valued function to differentiate impure function f(z) result(fz) use kinds real(rk), dimension(:), intent(in) :: z !! vector variable real(rk) :: fz !! scalar function end function f end interface do i = 1, size(x) temp_x = 0.0_rk temp_x(i) = x(i) dfdx(i) = (f(temp_x+h) - f(temp_x)) / h end do end function finite_difference_forward_T0_T1