complex_step_derivative_T0_T0 Function

private impure function complex_step_derivative_T0_T0(f, x, h) result(dfdx)

Calculates the derivative of a scalar-valued function w.r.t. a scalar-valued variable using complex step differentiation.

Arguments

Type IntentOptional Attributes Name
private impure function f(z) result(fz)
Arguments
Type IntentOptional Attributes Name
complex(kind=rk), intent(in) :: z

scalar complex variable

Return Value complex(kind=rk)

scalar complex function

real(kind=rk), intent(in) :: x

scalar variable

real(kind=rk), intent(in) :: h

perturbation for complex step differentiation

Return Value real(kind=rk)

derivative of w.r.t.


Called by

proc~~complex_step_derivative_t0_t0~~CalledByGraph proc~complex_step_derivative_t0_t0 fordiff::complex_step_derivative_T0_T0 interface~derivative fordiff::derivative interface~derivative->proc~complex_step_derivative_t0_t0 program~test1 test1 program~test1->interface~derivative program~test2 test2 program~test2->interface~derivative program~test3 test3 program~test3->interface~derivative program~test4 test4 program~test4->interface~derivative program~test5 test5 program~test5->interface~derivative program~test6 test6 program~test6->interface~derivative

Source Code

   impure function complex_step_derivative_T0_T0(f, x, h) result(dfdx)
      real(rk), intent(in) :: x    !! scalar variable
      real(rk), intent(in) :: h    !! perturbation for complex step differentiation
      real(rk)             :: dfdx !! derivative of \(f\) w.r.t. \(x\)

      interface
         !! scalar-valued function to differentiate
         impure function f(z) result(fz)
            use kinds
            complex(rk), intent(in) :: z  !! scalar complex variable
            complex(rk)             :: fz !! scalar complex function
         end function f
      end interface

      ! Check for potential division by zero
      if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.'

      dfdx = aimag(f(cmplx(x, h, rk))) / h

   end function complex_step_derivative_T0_T0