program main !*****************************************************************************80 ! !! MAIN is the main program for TEST_ZERO_PRB. ! ! Discussion: ! ! TEST_ZERO_PRB demonstrates the use of the TEST_ZERO scalar test functions. ! ! Modified: ! ! 04 November 2006 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: max_root = 4 integer, parameter :: max_start = 4 real ( kind = 8 ), parameter :: fatol = 1.0D-06 real ( kind = 8 ) fx integer i integer, parameter :: max_step = 25 integer mprob integer nprob integer nroot integer nstart character ( len = 80 ) title real ( kind = 8 ) x real ( kind = 8 ), parameter :: xatol = 1.0D-06 real ( kind = 8 ) xmax real ( kind = 8 ) xmin real ( kind = 8 ) xroot(max_root) real ( kind = 8 ), parameter :: xrtol = 1.0D-06 real ( kind = 8 ) xstart(max_start) call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST_ZERO_PRB' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' Tests for the TEST_ZERO collection of sample' write ( *, '(a)' ) ' scalar nonlinear equations.' write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' Function value tolerance = ', fatol write ( *, '(a,g14.6)' ) ' Root absolute tolerance = ', xatol write ( *, '(a,g14.6)' ) ' Root relative tolerance = ', xrtol write ( *, '(a,i4)' ) ' Maximum number of steps = ', max_step ! ! Find out how many problems there are ! call p00_nprob ( mprob ) write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Number of problems available is ', mprob do nprob = 1, mprob ! ! Get the problem title. ! call p00_title ( nprob, title ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Problem number ', nprob write ( *, '(2x,a)' ) trim ( title ) if ( nprob == 16 ) then call p16_p_print ( ) end if ! ! Get the problem interval. ! call p00_interval ( nprob, xmin, xmax ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' We seek roots between' write ( *, '(2x,g14.6)' ) xmin write ( *, '(a)' ) ' and' write ( *, '(2x,g14.6)' ) xmax ! ! Print the exact solution. ! call p00_root ( nprob, max_root, nroot, xroot ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Tabulated solutions:' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' X F(X)' write ( *, '(a)' ) ' ' do i = 1, nroot x = xroot(i) call p00_fx ( nprob, x, fx ) write ( *, '(2x,2g16.8)' ) x, fx end do ! ! Get the starting points. ! call p00_start ( nprob, max_start, nstart, xstart ) write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Number of available starting points:', nstart write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' I XSTART(I), F(XSTART(I))' write ( *, '(a)' ) ' ' do i = 1, nstart call p00_fx ( nprob, xstart(i), fx ) write ( *, '(2x,i2,2x,2g16.8)' ) i, xstart(i), fx end do ! ! Bisection. ! call bisection_pre ( fatol, max_step, nprob, nstart, xatol, xstart ) ! ! Regula Falsi. ! call regula_falsi_pre ( fatol, max_step, nprob, nstart, xatol, xstart ) ! ! Brent's method. ! call brent_pre ( fatol, max_step, nprob, nstart, xatol, xrtol, xstart ) ! ! Muller. ! call muller_pre ( fatol, max_step, nprob, nstart, xatol, xrtol, xstart ) ! ! Secant. ! call secant_pre ( fatol, max_step, nprob, nstart, xatol, xmin, xmax, & xstart ) ! ! Newton's method. ! call newton_pre ( fatol, max_step, nprob, nstart, xatol, xmin, xmax, & xstart ) end do write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST_ZERO_PRB' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end subroutine bisection_pre ( fatol, max_step, nprob, nstart, xatol, xstart ) !*****************************************************************************80 ! !! BISECTION_PRE prepares for the bisection method. ! ! Modified: ! ! 07 September 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real ( kind = 8 ) FATOL, an absolute error tolerance for ! the function value of the root. If an approximate root X satisfies ! ABS ( F ( X ) ) <= FATOL, then X will be accepted as the ! root and the iteration will be terminated. ! ! Input, integer MAX_STEP, the maximum number of steps allowed ! for an iteration. ! ! Input, integer NPROB, the index of the function whose root is ! to be sought. ! ! Input, integer NSTART, the number of starting points supplied. ! ! Input, real ( kind = 8 ) XATOL, an absolute error tolerance for the root. ! ! Input, real ( kind = 8 ) XSTART(NSTART), several starting points for ! the iteration. ! implicit none integer nstart real ( kind = 8 ) fatol real ( kind = 8 ) fxa real ( kind = 8 ) fxb integer istart integer max_step integer nprob real ( kind = 8 ) xa real ( kind = 8 ) xatol real ( kind = 8 ) xb real ( kind = 8 ) xstart(nstart) do istart = 1, nstart - 1 ! ! Get two starting points. ! xa = xstart(istart) call p00_fx ( nprob, xa, fxa ) xb = xstart(istart+1) call p00_fx ( nprob, xb, fxb ) ! ! The method requires a change of sign interval. ! if ( ( 0.0D+00 <= fxa .and. fxb <= 0.0D+00 ) .or. & ( fxa <= 0.0D+00 .and. 0.0D+00 <= fxb ) ) then call bisection ( fatol, max_step, nprob, xatol, xa, xb, fxa, fxb ) end if end do return end subroutine brent_pre ( fatol, max_step, nprob, nstart, xatol, xrtol, xstart ) !*****************************************************************************80 ! !! BRENT_PRE prepares for the Brent method. ! ! Modified: ! ! 07 September 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real ( kind = 8 ) FATOL, an absolute error tolerance for ! the function value of the root. If an approximate root X satisfies ! ABS ( F ( X ) ) <= FATOL, then X will be accepted as the ! root and the iteration will be terminated. ! ! Input, integer MAX_STEP, the maximum number of steps allowed ! for an iteration. ! ! Input, integer NPROB, the index of the function whose root is ! to be sought. ! ! Input, integer NSTART, the number of starting points supplied. ! ! Input, real ( kind = 8 ) XATOL, XRTOL, absolute and relative error ! tolerances for the root. ! ! Input, real ( kind = 8 ) XSTART(NSTART), several starting points ! for the iteration. ! implicit none integer nstart real ( kind = 8 ) fatol real ( kind = 8 ) fxa real ( kind = 8 ) fxb integer istart integer max_step integer nprob real ( kind = 8 ) xa real ( kind = 8 ) xatol real ( kind = 8 ) xb real ( kind = 8 ) xrtol real ( kind = 8 ) xstart(nstart) do istart = 1, nstart - 1 ! ! Get two starting points. ! xa = xstart(istart) call p00_fx ( nprob, xa, fxa ) xb = xstart(istart+1) call p00_fx ( nprob, xb, fxb ) ! ! The method requires a change of sign interval. ! if ( ( 0.0D+00 <= fxa .and. fxb <= 0.0D+00 ) .or. & ( fxa <= 0.0D+00 .and. 0.0D+00 <= fxb ) ) then call brent ( fatol, max_step, nprob, xatol, xrtol, xa, xb, fxa, fxb ) end if end do return end subroutine muller_pre ( fatol, max_step, nprob, nstart, xatol, xrtol, xstart ) !*****************************************************************************80 ! !! MULLER_PRE prepares for Muller's method. ! ! Modified: ! ! 07 September 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real ( kind = 8 ) FATOL, an absolute error tolerance for ! the function value of the root. If an approximate root X satisfies ! ABS ( F ( X ) ) <= FATOL, then X will be accepted as the ! root and the iteration will be terminated. ! ! Input, integer MAX_STEP, the maximum number of steps allowed ! for an iteration. ! ! Input, integer NPROB, the index of the function whose root is ! to be sought. ! ! Input, integer NSTART, the number of starting points supplied. ! ! Input, real ( kind = 8 ) XATOL, an absolute error tolerance for the root. ! ! Input, real ( kind = 8 ) XSTART(NSTART), several starting points for ! the iteration. ! implicit none integer nstart real ( kind = 8 ) fatol real ( kind = 8 ) fxa real ( kind = 8 ) fxb real ( kind = 8 ) fxc integer istart integer max_step integer nprob real ( kind = 8 ) xa real ( kind = 8 ) xatol real ( kind = 8 ) xb real ( kind = 8 ) xc real ( kind = 8 ) xrtol real ( kind = 8 ) xstart(nstart) do istart = 1, nstart - 2 ! ! Get three starting points. ! xa = xstart(istart) call p00_fx ( nprob, xa, fxa ) xb = xstart(istart+1) call p00_fx ( nprob, xb, fxb ) xc = xstart(istart+2) call p00_fx ( nprob, xc, fxc ) call muller ( fatol, max_step, nprob, xatol, xrtol, xa, xb, xc, fxa, & fxb, fxc ) end do return end subroutine newton_pre ( fatol, max_step, nprob, nstart, xatol, xmin, xmax, & xstart ) !*****************************************************************************80 ! !! NEWTON_PRE prepares for the Newton method. ! ! Modified: ! ! 07 September 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real ( kind = 8 ) FATOL, an absolute error tolerance for the ! function value of the root. If an approximate root X satisfies ! ABS ( F ( X ) ) <= FATOL, then X will be accepted as the ! root and the iteration will be terminated. ! ! Input, integer MAX_STEP, the maximum number of steps allowed ! for an iteration. ! ! Input, integer NPROB, the index of the function whose root is ! to be sought. ! ! Input, integer NSTART, the number of starting points supplied. ! ! Input, real ( kind = 8 ) XATOL, an absolute error tolerance for the root. ! ! Input, real ( kind = 8 ) XSTART(NSTART), several starting points ! for the iteration. ! implicit none integer nstart real ( kind = 8 ) fatol real ( kind = 8 ) fxa integer istart integer max_step integer nprob real ( kind = 8 ) xa real ( kind = 8 ) xatol real ( kind = 8 ) xmax real ( kind = 8 ) xmin real ( kind = 8 ) xstart(nstart) do istart = 1, nstart xa = xstart(istart) call p00_fx ( nprob, xa, fxa ) call newton ( fatol, max_step, nprob, xatol, xmin, xmax, xa, fxa ) end do return end subroutine regula_falsi_pre ( fatol, max_step, nprob, nstart, xatol, xstart ) !*****************************************************************************80 ! !! REGULA_FALSI_PRE prepares for the regula falsi method. ! ! Modified: ! ! 07 September 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real ( kind = 8 ) FATOL, an absolute error tolerance for the ! function value of the root. If an approximate root X satisfies ! ABS ( F ( X ) ) <= FATOL, then X will be accepted as the ! root and the iteration will be terminated. ! ! Input, integer MAX_STEP, the maximum number of steps allowed ! for an iteration. ! ! Input, integer NPROB, the index of the function whose root is ! to be sought. ! ! Input, integer NSTART, the number of starting points supplied. ! ! Input, real ( kind = 8 ) XATOL, an absolute error tolerance for the root. ! ! Input, real ( kind = 8 ) XSTART(NSTART), several starting points ! for the iteration. ! implicit none integer nstart real ( kind = 8 ) fatol real ( kind = 8 ) fxa real ( kind = 8 ) fxb integer istart integer max_step integer nprob real ( kind = 8 ) xa real ( kind = 8 ) xatol real ( kind = 8 ) xb real ( kind = 8 ) xstart(nstart) do istart = 1, nstart - 1 ! ! Get two starting points. ! xa = xstart(istart) call p00_fx ( nprob, xa, fxa ) xb = xstart(istart+1) call p00_fx ( nprob, xb, fxb ) ! ! The method requires a change of sign interval. ! if ( ( 0.0D+00 <= fxa .and. fxb <= 0.0D+00 ) .or. & ( fxa <= 0.0D+00 .and. 0.0D+00 <= fxb ) ) then call regula_falsi ( fatol, max_step, nprob, xatol, xa, xb, fxa, fxb ) end if end do return end subroutine secant_pre ( fatol, max_step, nprob, nstart, xatol, xmin, xmax, & xstart ) !*****************************************************************************80 ! !! SECANT_PRE prepares for the secant method. ! ! Modified: ! ! 07 September 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real ( kind = 8 ) FATOL, an absolute error tolerance for the ! function value of the root. If an approximate root X satisfies ! ABS ( F ( X ) ) <= FATOL, then X will be accepted as the ! root and the iteration will be terminated. ! ! Input, integer MAX_STEP, the maximum number of steps allowed ! for an iteration. ! ! Input, integer NPROB, the index of the function whose root is ! to be sought. ! ! Input, integer NSTART, the number of starting points supplied. ! ! Input, real ( kind = 8 ) XATOL, an absolute error tolerance for the root. ! ! Input, real ( kind = 8 ) XSTART(NSTART), several starting points ! for the iteration. ! implicit none integer nstart real ( kind = 8 ) fatol real ( kind = 8 ) fxa real ( kind = 8 ) fxb integer istart integer max_step integer nprob real ( kind = 8 ) xa real ( kind = 8 ) xatol real ( kind = 8 ) xb real ( kind = 8 ) xmax real ( kind = 8 ) xmin real ( kind = 8 ) xstart(nstart) do istart = 1, nstart - 1 ! ! Get two starting points. ! xa = xstart(istart) call p00_fx ( nprob, xa, fxa ) xb = xstart(istart+1) call p00_fx ( nprob, xb, fxb ) call secant ( fatol, max_step, nprob, xatol, xmin, xmax, xa, xb, fxa, fxb ) end do return end