c_fdjac_1n_sub Subroutine

subroutine c_fdjac_1n_sub(funcv, x, fjac, epsfcn)

Arguments

Type IntentOptional Attributes Name
subroutine funcv(n, x, y)
Arguments
Type IntentOptional Attributes Name
integer :: n
real(kind=8), intent(in), dimension(n) :: x
complex(kind=8) :: y
real(kind=8) :: x(:)
complex(kind=8) :: fjac(size(x))
real(kind=8), optional :: epsfcn

Source Code

subroutine c_fdjac_1n_sub(funcv,x,fjac,epsfcn)
  interface 
     subroutine funcv(n,x,y)
       integer                         :: n
       real(8),dimension(n),intent(in) :: x
       complex(8)                      :: y
     end subroutine funcv
  end interface
  integer          ::  n
  real(8)          ::  x(:)
  complex(8)       ::  fvec
  complex(8)       ::  fjac(size(x))
  real(8),optional ::  epsfcn
  real(8)          ::  eps,eps_
  real(8)          ::  epsmch
  real(8)          ::  h,temp
  complex(8)       ::  wa1
  complex(8)       ::  wa2
  integer          :: i,j,k
  n=size(x)
  eps_= 0.d0; if(present(epsfcn))eps_=epsfcn
  epsmch = epsilon(epsmch)
  eps  = sqrt(max(eps_,epsmch))
  !  Evaluate the function
  call funcv(n,x,fvec)
  !  Computation of dense approximate jacobian.
  do j=1,n
     temp = x(j)
     h    = eps*abs(temp)
     if(h==0.d0) h = eps
     x(j) = temp + h
     call funcv(n,x,wa1)
     x(j) = temp
     fjac(j) = (wa1-fvec)/h
  enddo
  return
end subroutine c_fdjac_1n_sub