program main c*********************************************************************72 c cc zero_chandrupatla_test() tests zero_chandrupatla(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 19 March 2024 c c Author: c c John Burkardt c implicit none double precision a double precision b double precision, external :: f_01 double precision, external :: f_02 double precision, external :: f_03 double precision, external :: f_04 double precision, external :: f_05 double precision, external :: f_06 double precision, external :: f_07 double precision, external :: f_08 double precision, external :: f_09 character ( len = 100 ) title call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'zero_chandrupatla_test():' write ( *, '(a)' ) ' Fortran77 version' write ( *, '(a)' ) ' zero_chandrupatla() seeks a root of a' write ( *, '(a)' ) ' function f(x) in an interval [a,b].' a = 2.0 b = 3.0 title = 'f_01(x) = x**3 - 2 x - 5' call zero_chandrupatla_example ( f_01, a, b, title ) a = 0.5 b = 1.51 title = 'f_02(x) = 1 - 1/x**2' call zero_chandrupatla_example ( f_02, a, b, title ) a = 0.0 b = 5.0 title = 'f_03(x) = ( x - 3 )**3' call zero_chandrupatla_example ( f_03, a, b, title ) a = 0.0 b = 5.0 title = 'f_04(x) = 6 * ( x - 2 )**5' call zero_chandrupatla_example ( f_04, a, b, title ) a = -1.0 b = 4.0 title = 'f_05(x) = x**9' call zero_chandrupatla_example ( f_05, a, b, title ) a = -1.0 b = 4.0 title = 'f_06(x) = x**19' call zero_chandrupatla_example ( f_06, a, b, title ) a = -1.0 b = 4.0 title = 'f_07(x) = x e**(-1/x2)' call zero_chandrupatla_example ( f_07, a, b, title ) a = 0.0002 b = 2.0 title = 'f_08(x) = ' // & '-(3062(1-xi)e**(-x)/(xi+(1-xi)e**(-x)) - 1013 + 1628/x' call zero_chandrupatla_example ( f_08, a, b, title ) a = 0.0002 b = 1.0 title = 'f_09(x) = e**x - 2 - 0.01/x**2 + 0.000002/x**3' call zero_chandrupatla_example ( f_09, a, b, title ) c c Terminate. c write ( *, '(a)' ) '' write ( *, '(a)' ) 'zero_chandrupatla_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine zero_chandrupatla_example ( f, a, b, title ) c*********************************************************************72 c cc zero_chandrupatla_example() tests zero_chandrupatla() on a test function. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 19 March 2024 c c Author: c c John Burkardt c c Input: c c function f ( x ): the user-supplied function. c c real a, b: the endpoints of the change of sign interval. c c string title: a title for the problem. c implicit none double precision a double precision b integer calls double precision, external :: f double precision fa double precision fb double precision fz character ( len = * ) title double precision z call zero_chandrupatla ( f, a, b, z, fz, calls ) fz = f ( z ) fa = f ( a ) fb = f ( b ) write ( *, '(a)' ) '' write ( *, '(2x,a)' ) trim ( title ) write ( *, '(a)' ) '' write ( *, '(a)' ) ' A Z B' write ( *, '(a)' ) ' F(A) F(Z) F(B)' write ( *, '(a)' ) '' write ( *, '(2x,f14.6,2x,f14.6,2x,f14.6)' ) a, z, b write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) fa, fz, fb write ( *, '(a,i4)' ) ' Number of calls to F = ', calls return end function f_01 ( x ) c*********************************************************************72 c cc f_01() evaluates function 1. c implicit none double precision f_01 double precision x f_01 = x**3 - 2.0 * x - 5.0 return end function f_02 ( x ) c*********************************************************************72 c cc f_02() evaluates function 2. c implicit none double precision f_02 double precision x f_02 = 1.0 - 1.0 / x**2 return end function f_03 ( x ) c*********************************************************************72 c cc f_03() evaluates function 3. c implicit none double precision f_03 double precision x f_03 = ( x - 3.0 )**3 return end function f_04 ( x ) c*********************************************************************72 c cc f_04() evaluates function 4. c implicit none double precision f_04 double precision x f_04 = 6.0 * ( x - 2.0 )**5 return end function f_05 ( x ) c*********************************************************************72 c cc f_05() evaluates function 5. c implicit none double precision f_05 double precision x f_05 = x**9 return end function f_06 ( x ) c*********************************************************************72 c cc f_06() evaluates function 6. c implicit none double precision f_06 double precision x f_06 = x**19 return end function f_07 ( x ) c*********************************************************************72 c cc f_07() evaluates function 7. c implicit none double precision f_07 double precision x if ( abs ( x ) < 3.8D-04 ) then f_07 = 0.0 else f_07 = x * exp ( - ( 1.0 / x**2 ) ) end if return end function f_08 ( x ) c*********************************************************************72 c cc f_08() evaluates function 8. c implicit none double precision bot double precision f_08 double precision top double precision x double precision xi xi = 0.61489 top = ( 3062.0 * ( 1.0 - xi ) * exp ( - x ) ) bot = ( xi + ( 1.0 - xi ) * exp ( - x ) ) f_08 = - top / bot - 1013.0 + 1628.0 / x return end function f_09 ( x ) c*********************************************************************72 c cc f_09() evaluates function 9. c implicit none double precision f_09 double precision x f_09 = exp ( x ) - 2.0 - 0.01D+00 / x**2 + 0.000002D+00 / x**3 return end subroutine timestamp ( ) c*********************************************************************72 c cc timestamp() prints the YMDHMS date as a timestamp. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 12 June 2014 c c Author: c c John Burkardt c implicit none character * ( 8 ) ampm integer d character * ( 8 ) date integer h integer m integer mm character * ( 9 ) month(12) integer n integer s character * ( 10 ) time integer y save month data month / & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' / call date_and_time ( date, time ) read ( date, '(i4,i2,i2)' ) y, m, d read ( time, '(i2,i2,i2,1x,i3)' ) h, n, s, mm if ( h .lt. 12 ) then ampm = 'AM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h .lt. 12 ) then ampm = 'PM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 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