finite_difference_T1_T1 Function

private impure function finite_difference_T1_T1(f, x, h, method) result(dfdx)

Calculates the derivative of a vector-valued function w.r.t. a vector-valued variable using finite difference methods (forward, backward, central).

Arguments

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

vector variable

Return Value real(kind=rk), dimension(:), allocatable

vector function

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

vector variable

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

perturbation for finite difference methods

character(len=*), intent(in) :: method

finite difference method (forward, backward, central)

Return Value real(kind=rk), dimension(:,:), allocatable

derivative of w.r.t.


Calls

proc~~finite_difference_t1_t1~~CallsGraph proc~finite_difference_t1_t1 fordiff::finite_difference_T1_T1 proc~finite_difference_backward_t1_t1 fordiff::finite_difference_backward_T1_T1 proc~finite_difference_t1_t1->proc~finite_difference_backward_t1_t1 proc~finite_difference_central_t1_t1 fordiff::finite_difference_central_T1_T1 proc~finite_difference_t1_t1->proc~finite_difference_central_t1_t1 proc~finite_difference_forward_t1_t1 fordiff::finite_difference_forward_T1_T1 proc~finite_difference_t1_t1->proc~finite_difference_forward_t1_t1

Called by

proc~~finite_difference_t1_t1~~CalledByGraph proc~finite_difference_t1_t1 fordiff::finite_difference_T1_T1 interface~derivative fordiff::derivative interface~derivative->proc~finite_difference_t1_t1 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 finite_difference_T1_T1(f,x,h,method) result(dfdx)
      real(rk), dimension(:), intent(in)    :: x       !! vector variable
      real(rk),               intent(in)    :: h       !! perturbation for finite difference methods
      character(*),           intent(in)    :: method  !! finite difference method (forward, backward, central)
      real(rk), dimension(:,:), allocatable :: dfdx    !! derivative of \(\mathbf{f}\) w.r.t. \(\mathbf{x}\)

      interface
         !! vector-valued function to differentiate
         impure function f(z) result(fz)
            use kinds
            real(rk), dimension(:), intent(in)  :: z  !! vector variable
            real(rk), dimension(:), allocatable :: fz !! vector function
         end function f
      end interface

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

      select case (method)
       case('forward')
         dfdx = finite_difference_forward_T1_T1(f,x,h)
       case('backward')
         dfdx = finite_difference_backward_T1_T1(f,x,h)
       case('central')
         dfdx = finite_difference_central_T1_T1(f,x,h)
      end select

   end function finite_difference_T1_T1