program main !*****************************************************************************80 ! !! test_zero_test() tests test_zero(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 29 March 2025 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'test_zero_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Test test_zero().' call test01 ( ) ! ! Terminate. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'test_zero_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop 0 end subroutine test01 ( ) !*****************************************************************************80 ! !! TEST01 calls all the test problems. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 16 May 2011 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) integer, parameter :: max_root = 4 integer, parameter :: max_start = 4 real ( kind = rk8 ), parameter :: fatol = 1.0D-06 real ( kind = rk8 ) fx real ( kind = rk8 ) fxa real ( kind = rk8 ) fxb real ( kind = rk8 ) fxc integer i integer, parameter :: max_step = 25 integer prob integer prob_num real ( kind = rk8 ) r8_sign real ( kind = rk8 ) range(2) integer root_num integer start_num character ( len = 80 ) title real ( kind = rk8 ) x real ( kind = rk8 ) xa real ( kind = rk8 ), parameter :: xatol = 1.0D-06 real ( kind = rk8 ) xb real ( kind = rk8 ) xc real ( kind = rk8 ) xmax real ( kind = rk8 ) xmin real ( kind = rk8 ), parameter :: xrtol = 1.0D-06 real ( kind = rk8 ) xstart(max_start) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST01' write ( *, '(a)' ) ' Try every test problem.' 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_prob_num ( prob_num ) write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Number of problems available is ', prob_num do prob = 1, prob_num ! ! Get the problem title. ! call p00_title ( prob, title ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Problem number ', prob write ( *, '(2x,a)' ) trim ( title ) ! ! Get the problem interval. ! call p00_range ( prob, range ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' We seek roots between' write ( *, '(2x,g14.6)' ) range(1) write ( *, '(a)' ) ' and' write ( *, '(2x,g14.6)' ) range(2) ! ! Get the number of roots. ! call p00_root_num ( prob, root_num ) write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Number of known roots = ', root_num ! ! Get the roots. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' I X F(X)' write ( *, '(a)' ) ' ' do i = 1, root_num call p00_root ( prob, i, x ) call p00_fx ( prob, x, fx ) write ( *, '(2x,i4,2g16.8)' ) i, x, fx end do ! ! Get the number of starting points. ! call p00_start_num ( prob, start_num ) write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Number of starting points = ', start_num ! ! Get the starting points. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' I XSTART(I), F(XSTART(I))' write ( *, '(a)' ) ' ' do i = 1, start_num call p00_start ( prob, i, xstart(i) ) call p00_fx ( prob, xstart(i), fx ) write ( *, '(2x,i2,2x,2g16.8)' ) i, xstart(i), fx end do ! ! Bisection. ! call p00_start ( prob, 1, xa ) call p00_fx ( prob, xa, fxa ) do i = 2, start_num call p00_start ( prob, i, xb ) call p00_fx ( prob, xb, fxb ) if ( r8_sign ( fxa ) /= r8_sign ( fxb ) ) then call bisection ( fatol, max_step, prob, xatol, xa, xb, fxa, fxb ) exit end if end do ! ! Brent's method. ! call p00_start ( prob, 1, xa ) call p00_fx ( prob, xa, fxa ) do i = 2, start_num call p00_start ( prob, i, xb ) call p00_fx ( prob, xb, fxb ) if ( r8_sign ( fxa ) /= r8_sign ( fxb ) ) then call brent ( fatol, max_step, prob, xatol, xrtol, xa, xb, fxa, fxb ) exit end if end do ! ! Muller's method. ! if ( 3 <= start_num ) then call p00_start ( prob, 1, xa ) call p00_fx ( prob, xa, fxa ) call p00_start ( prob, 2, xb ) call p00_fx ( prob, xb, fxb ) call p00_start ( prob, 3, xc ) call p00_fx ( prob, xc, fxc ) call muller ( fatol, max_step, prob, xatol, xrtol, xa, xb, xc, & fxa, fxb, fxc ) end if ! ! Newton. ! do i = 1, start_num call p00_start ( prob, i, xa ) call p00_fx ( prob, xa, fxa ) call newton ( fatol, max_step, prob, xatol, xmin, xmax, xa, fxa ) end do ! ! Regula Falsi. ! call p00_start ( prob, 1, xa ) call p00_fx ( prob, xa, fxa ) do i = 2, start_num call p00_start ( prob, i, xb ) call p00_fx ( prob, xb, fxb ) if ( r8_sign ( fxa ) /= r8_sign ( fxb ) ) then call regula_falsi ( fatol, max_step, prob, xatol, xa, xb, fxa, fxb ) exit end if end do ! ! Secant. ! do i = 1, start_num - 1 call p00_start ( prob, i, xa ) call p00_fx ( prob, xa, fxa ) call p00_start ( prob, i + 1, xb ) call p00_fx ( prob, xb, fxb ) call secant ( fatol, max_step, prob, xatol, xmin, xmax, xa, xb, fxa, fxb ) end do end do return end subroutine timestamp ( ) !*****************************************************************************80 ! !! timestamp() prints the current YMDHMS date as a time stamp. ! ! Example: ! ! 31 May 2001 9:45:54.872 AM ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 18 May 2013 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) character ( len = 8 ) ampm integer d integer h integer m integer mm character ( len = 9 ), parameter, dimension(12) :: month = (/ & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' /) integer n integer s integer values(8) integer y call date_and_time ( values = values ) y = values(1) m = values(2) d = values(3) h = values(5) n = values(6) s = values(7) mm = values(8) if ( h < 12 ) then ampm = 'AM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h < 12 ) then ampm = 'PM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm ) return end