Calculates the derivative of a vector-valued function w.r.t. a vector-valued variable using complex step differentiation.
Type | Intent | Optional | Attributes | Name | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
private impure function f(z) result(fz)Arguments
Return Value complex(kind=rk), dimension(:), allocatablevector complex function |
||||||||||||||||||||
real(kind=rk), | intent(in), | dimension(:) | :: | x |
vector variable |
|||||||||||||||
real(kind=rk), | intent(in) | :: | h |
perturbation for complex step differentiation |
derivative of w.r.t.
impure function complex_step_derivative_T1_T1(f, x, h) result(dfdx) real(rk), dimension(:), intent(in) :: x !! vector variable real(rk), intent(in) :: h !! perturbation for complex step differentiation real(rk), dimension(:,:), allocatable :: dfdx !! derivative of \(\mathbf{f}\) w.r.t. \(\mathbf{f}\) real(rk), dimension(size(x)) :: temp_x !! temporary vector variable integer :: i !! loop index interface !! vector-valued function to differentiate impure function f(z) result(fz) use kinds complex(rk), dimension(:), intent(in) :: z !! vector complex variable complex(rk), dimension(:), allocatable :: fz !! vector complex function end function f end interface allocate(dfdx(size(f(cmplx(x,kind=rk))),size(x))) if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.' do i = 1, size(x) temp_x = 0.0_rk temp_x(i) = x(i) dfdx(:,i) = aimag(f(cmplx(temp_x, h, rk))) / h end do end function complex_step_derivative_T1_T1