function digama ( x, ifault ) !*****************************************************************************80 ! !! DIGAMA calculates DIGAMMA ( X ) = d ( LOG ( GAMMA ( X ) ) ) / dX ! ! Modified: ! ! 18 January 2008 ! ! Author: ! ! Jose Bernardo ! FORTRAN90 version by John Burkardt ! ! Reference: ! ! Jose Bernardo, ! Algorithm AS 103: ! Psi ( Digamma ) Function, ! Applied Statistics, ! Volume 25, Number 3, 1976, pages 315-317. ! ! Parameters: ! ! Input, real ( kind = 8 ) X, the argument of the digamma function. ! 0 < X. ! ! Output, integer IFAULT, error flag. ! 0, no error. ! 1, X <= 0. ! ! Output, real ( kind = 8 ) DIGAMA, the value of the digamma function at X. ! implicit none real ( kind = 8 ), parameter :: c = 8.5D+00 real ( kind = 8 ), parameter :: d1 = -0.5772156649D+00 real ( kind = 8 ) digama integer ( kind = 4 ) ifault real ( kind = 8 ) r real ( kind = 8 ), parameter :: s = 0.00001D+00 real ( kind = 8 ), parameter :: s3 = 0.08333333333D+00 real ( kind = 8 ), parameter :: s4 = 0.0083333333333D+00 real ( kind = 8 ), parameter :: s5 = 0.003968253968D+00 real ( kind = 8 ) x real ( kind = 8 ) y ! ! Check the input. ! if ( x <= 0.0D+00 ) then digama = 0.0D+00 ifault = 1 return end if ! ! Initialize. ! ifault = 0 y = x digama = 0.0D+00 ! ! Use approximation if argument <= S. ! if ( y <= s ) then digama = d1 - 1.0D+00 / y return end if ! ! Reduce to DIGAMA(X + N) where (X + N) >= C. ! do while ( y < c ) digama = digama - 1.0D+00 / y y = y + 1.0D+00 end do ! ! Use Stirling's (actually de Moivre's) expansion if argument > C. ! r = 1.0D+00 / y digama = digama + log ( y ) - 0.5D+00 * r r = r * r digama = digama - r * ( s3 - r * ( s4 - r * s5 ) ) return end subroutine psi_values ( n_data, x, fx ) !*****************************************************************************80 ! !! PSI_VALUES returns some values of the Psi or Digamma function. ! ! Discussion: ! ! In Mathematica, the function can be evaluated by: ! ! PolyGamma[x] ! ! or ! ! PolyGamma[0,x] ! ! PSI(X) = d ln ( Gamma ( X ) ) / d X = Gamma'(X) / Gamma(X) ! ! PSI(1) = -Euler's constant. ! ! PSI(X+1) = PSI(X) + 1 / X. ! ! Modified: ! ! 17 August 2004 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! Milton Abramowitz, Irene Stegun, ! Handbook of Mathematical Functions, ! National Bureau of Standards, 1964, ! ISBN: 0-486-61272-4, ! LC: QA47.A34. ! ! Stephen Wolfram, ! The Mathematica Book, ! Fourth Edition, ! Cambridge University Press, 1999, ! ISBN: 0-521-64314-7, ! LC: QA76.95.W65. ! ! Parameters: ! ! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0 ! before the first call. On each call, the routine increments N_DATA by 1, ! and returns the corresponding data; when there is no more data, the ! output value of N_DATA will be 0 again. ! ! Output, real ( kind = 8 ) X, the argument of the function. ! ! Output, real ( kind = 8 ) FX, the value of the function. ! implicit none integer ( kind = 4 ), parameter :: n_max = 11 real ( kind = 8 ) fx real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ & -0.5772156649015329D+00, & -0.4237549404110768D+00, & -0.2890398965921883D+00, & -0.1691908888667997D+00, & -0.6138454458511615D-01, & 0.3648997397857652D-01, & 0.1260474527734763D+00, & 0.2085478748734940D+00, & 0.2849914332938615D+00, & 0.3561841611640597D+00, & 0.4227843350984671D+00 /) integer ( kind = 4 ) n_data real ( kind = 8 ) x real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ & 1.0D+00, & 1.1D+00, & 1.2D+00, & 1.3D+00, & 1.4D+00, & 1.5D+00, & 1.6D+00, & 1.7D+00, & 1.8D+00, & 1.9D+00, & 2.0D+00 /) if ( n_data < 0 ) then n_data = 0 end if n_data = n_data + 1 if ( n_max < n_data ) then n_data = 0 x = 0.0D+00 fx = 0.0D+00 else x = x_vec(n_data) fx = fx_vec(n_data) end if return end subroutine timestamp ( ) !*****************************************************************************80 ! !! TIMESTAMP prints the current YMDHMS date as a time stamp. ! ! Example: ! ! 31 May 2001 9:45:54.872 AM ! ! Modified: ! ! 06 August 2005 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! None ! implicit none 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