brent Subroutine

subroutine brent(func, xmin, brack, tol, niter)

Arguments

Type IntentOptional Attributes Name
function func(x)
Arguments
Type IntentOptional Attributes Name
real(kind=8) :: x
Return Value real(kind=8)
real(kind=8), intent(inout) :: xmin
real(kind=8), optional, dimension(:) :: brack
real(kind=8), optional :: tol
integer, optional :: niter

Calls

proc~~brent~~CallsGraph proc~brent brent bracket bracket proc~brent->bracket brent_optimize brent_optimize proc~brent->brent_optimize

Source Code

subroutine brent(func,xmin,brack,tol,niter)
  interface
     function func(x)
       real(8) :: x
       real(8) :: func
     end function func
  end interface
  real(8),intent(inout)         :: xmin
  real(8),dimension(:),optional :: brack
  real(8),optional              :: tol
  integer,optional              :: niter
  real(8)                       :: tol_
  integer                       :: niter_
  integer                       :: iter
  real(8)                       :: ax,xx,bx,fa,fx,fb,fret
  !
  tol_=1d-9;if(present(tol))tol_=tol
  Niter_=200;if(present(Niter))Niter_=Niter
  !
  if(present(brack))then
     select case(size(brack))
     case(1)
        stop "Brent error: calling brent with size(brack)==1. None or two points are necessary."
     case(2)
        ax = brack(1)
        xx = brack(2)
        call bracket(ax,xx,bx,fa,fx,fb,func)
     case (3)
        ax = brack(1)
        xx = brack(2)
        bx = brack(3)
     end select
  else
     ax=0d0
     xx=1d0
     call bracket(ax,xx,bx,fa,fx,fb,func)
  endif
  fret=brent_optimize(ax,xx,bx,func,tol_,niter_,xmin)
end subroutine brent