JHUGen MELA  JHUGen v7.5.6, MELA v2.4.2
Matrix element calculations as used in JHUGen.
hto_root_find2 Module Reference

Functions/Subroutines

real *8 function hto_zeroin (f, ax, bx, aerr, rerr)
 

Function/Subroutine Documentation

◆ hto_zeroin()

real*8 function hto_root_find2::hto_zeroin (   f,
real*8, intent(in)  ax,
real*8, intent(in)  bx,
real*8, intent(in)  aerr,
real*8, intent(in)  rerr 
)

Definition at line 3428 of file CALLING_cpHTO.f.

3428 *
3429  USE hto_rootw
3430 *
3431 ! Code converted using TO_F90 by Alan Miller
3432 ! Date: 2003-07-14 Time: 12:32:54
3433 
3434 !-----------------------------------------------------------------------
3435 
3436 ! FINDING A ZERO OF THE FUNCTION F(X) IN THE INTERVAL (AX,BX)
3437 
3438 ! ------------------------
3439 
3440 ! INPUT...
3441 
3442 ! F FUNCTION SUBPROGRAM WHICH EVALUATES F(X) FOR ANY X IN THE
3443 ! CLOSED INTERVAL (AX,BX). IT IS ASSUMED THAT F IS CONTINUOUS,
3444 ! AND THAT F(AX) AND F(BX) HAVE DIFFERENT SIGNS.
3445 ! AX LEFT ENDPOINT OF THE INTERVAL
3446 ! BX RIGHT ENDPOINT OF THE INTERVAL
3447 ! AERR THE ABSOLUTE ERROR TOLERANCE TO BE SATISFIED
3448 ! RERR THE RELATIVE ERROR TOLERANCE TO BE SATISFIED
3449 
3450 ! OUTPUT...
3451 
3452 ! ABCISSA APPROXIMATING A ZERO OF F IN THE INTERVAL (AX,BX)
3453 
3454 !-----------------------------------------------------------------------
3455 ! ZEROIN IS A SLIGHTLY MODIFIED TRANSLATION OF THE ALGOL PROCEDURE
3456 ! ZERO GIVEN BY RICHARD BRENT IN ALGORITHMS FOR MINIMIZATION WITHOUT
3457 ! DERIVATIVES, PRENTICE-HALL, INC. (1973).
3458 !-----------------------------------------------------------------------
3459 
3460  IMPLICIT NONE
3461  real*8, INTENT(IN) :: ax
3462  real*8, INTENT(IN) :: bx
3463  real*8, INTENT(IN) :: aerr
3464  real*8, INTENT(IN) :: rerr
3465  real*8 :: fn_val
3466 *
3467 * EXTERNAL f
3468 *
3469  INTERFACE
3470  FUNCTION f(x) RESULT(fn_val)
3471  IMPLICIT NONE
3472  real*8, INTENT(IN) :: x
3473  real*8 :: fn_val
3474  END FUNCTION f
3475  END INTERFACE
3476 *
3477  real*8 :: a,b,c,d,e,eps,fa,fb,fc,tol,xm,p,q,r,s,atol,rtol
3478 
3479 ! COMPUTE EPS, THE RELATIVE MACHINE PRECISION
3480 
3481  eps= epsilon(0.0d0)
3482 
3483 ! INITIALIZATION
3484 
3485  a= ax
3486  b= bx
3487  fa= f(a)
3488  fb= f(b)
3489  IF(fa*fb.gt.0.d0) THEN
3490  inc= 1
3491  ENDIF
3492  atol= 0.5d0*aerr
3493  rtol= max(0.5d0*rerr, 2.0d0*eps)
3494 
3495 ! BEGIN STEP
3496 
3497  10 c= a
3498  fc= fa
3499  d= b-a
3500  e= d
3501  20 IF(abs(fc) < abs(fb)) THEN
3502  a= b
3503  b= c
3504  c= a
3505  fa= fb
3506  fb= fc
3507  fc= fa
3508  END IF
3509 
3510 ! CONVERGENCE TEST
3511 
3512  tol= rtol*max(abs(b),abs(c))+atol
3513  xm= 0.5d0*(c-b)
3514  IF(abs(xm) > tol) THEN
3515  IF(fb /= 0.0d0) THEN
3516 
3517 ! IS BISECTION NECESSARY
3518 
3519  IF(abs(e) >= tol) THEN
3520  IF(abs(fa) > abs(fb)) THEN
3521 
3522 ! IS QUADRATIC INTERPOLATION POSSIBLE
3523 
3524  IF(a == c) THEN
3525 
3526 ! LINEAR INTERPOLATION
3527 
3528  s= fb/fc
3529  p= (c-b)*s
3530  q= 1.0d0-s
3531  ELSE
3532 
3533 ! INVERSE QUADRATIC INTERPOLATION
3534 
3535  q= fa/fc
3536  r= fb/fc
3537  s= fb/fa
3538  p= s*((c-b)*q*(q-r)-(b-a)*(r-1.0d0))
3539  q= (q-1.0d0)*(r-1.0d0)*(s-1.0d0)
3540  ENDIF
3541 
3542 ! ADJUST SIGNS
3543 
3544  IF(p > 0.0d0) q= -q
3545  p= abs(p)
3546 
3547 ! IS INTERPOLATION ACCEPTABLE
3548 
3549  IF(2.0*p < (3.0*xm*q-abs(tol*q))) THEN
3550  IF(p < abs(0.5d0*e*q)) THEN
3551  e= d
3552  d= p/q
3553  GO TO 30
3554  ENDIF
3555  ENDIF
3556  ENDIF
3557  ENDIF
3558 
3559 ! BISECTION
3560 
3561  d= xm
3562  e= d
3563 
3564 ! COMPLETE STEP
3565 
3566  30 a= b
3567  fa= fb
3568  IF(abs(d) > tol) b= b+d
3569  IF(abs(d) <= tol) b= b+sign(tol,xm)
3570  fb= f(b)
3571  IF(fb*(fc/abs(fc)) > 0.0d0) GO TO 10
3572  GO TO 20
3573  ENDIF
3574  ENDIF
3575 
3576 ! DONE
3577 
3578  fn_val= b
3579  RETURN
hto_rootw
Definition: CALLING_cpHTO.f:245
hto_rootw::inc
integer inc
Definition: CALLING_cpHTO.f:246
hto_units::eps
real *8, parameter eps
Definition: CALLING_cpHTO.f:183