program main c*********************************************************************72 c cc sigmoid_test() tests sigmoid(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 24 March 2025 c c Author: c c John Burkardt c call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sigmoid_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Test sigmoid.' call sigmoid_coef_test ( ) call sigmoid_value_test ( ) c c Terminate. c write ( *, '(a)' ) '' write ( *, '(a)' ) 'sigmoid_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine sigmoid_coef_test ( ) c*********************************************************************72 c cc sigmoid_coef_test() tests sigmoid_coef(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 23 May 2024 c c Author: c c John Burkardt c implicit none double precision, allocatable :: coef(:) character ( len = 80 ) label integer n write ( *, '(a)' ) '' write ( *, '(a)' ) 'sigmoid_coef_test():' write ( *, '(a)' ) & ' sigmoid_coef() returns the coefficients of' write ( *, '(a)' ) & ' the expansion of the nth derivative of the sigmoid' write ( *, '(a)' ) & ' function in terms of powers of the sigmoid function.' do n = 0, 4 allocate ( coef(1:n+2) ) call sigmoid_coef ( n, coef ) write ( label, '(a,i1,a)' ) ' s^(', n, ')(x)' call sigmoid_poly_print ( n + 2, coef, label ) deallocate ( coef ) end do return end subroutine sigmoid_value_test ( ) c*********************************************************************72 c cc sigmoid_value_test() tests sigmoid_value(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 22 May 2024 c c Author: c c John Burkardt c implicit none integer, parameter :: nvec = 51 character ( len = 255 ) header integer i integer n double precision sigmoid_value double precision xvec(nvec) double precision yvec(nvec) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sigmoid_value_test():' write ( *, '(a)' ) & ' sigmoid_value() evaluates the nth derivative' write ( *, '(a)' ) ' of the sigmoid function at the location x.' do n = 0, 3 call r8vec_linspace ( nvec, -5.0D+00, +5.0D+00, xvec ) yvec(1:nvec) = 0.0D+00 do i = 1, nvec yvec(i) = sigmoid_value ( n, xvec(i) ) end do write ( header, '(a,i1)' ) 'sigmoid_', n call sigmoid_plot ( nvec, xvec, yvec, & trim ( header ) ) end do return end subroutine get_unit ( iunit ) c*********************************************************************72 c cc get_unit() returns a free FORTRAN unit number. c c Discussion: c c A "free" FORTRAN unit number is a value between 1 and 99 which c is not currently associated with an I/O device. A free FORTRAN unit c number is needed in order to open a file with the OPEN command. c c If IUNIT = 0, then no free FORTRAN unit could be found, although c all 99 units were checked (except for units 5, 6 and 9, which c are commonly reserved for console I/O). c c Otherwise, IUNIT is a value between 1 and 99, representing a c free FORTRAN unit. The code assumes that units 5 and 6 c are special, and will never return those values. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 26 October 2008 c c Author: c c John Burkardt c c Output: c c integer IUNIT, the free unit number. c implicit none integer i integer ios integer iunit logical lopen iunit = 0 do i = 1, 99 if ( i /= 5 .and. i /= 6 .and. i /= 9 ) then inquire ( unit = i, opened = lopen, iostat = ios ) if ( ios == 0 ) then if ( .not. lopen ) then iunit = i return end if end if end if end do return end subroutine sigmoid_plot ( nvec, xvec, yvec, header ) c*********************************************************************72 c cc sigmoid_plot() plots a sigmoid derivative. c c Discussion: c c Actually, we simply create two files for processing by gnuplot(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 23 May 2024 c c Author: c c John Burkardt c implicit none integer nvec character ( len = 255 ) command_filename integer command_unit character ( len = 255 ) data_filename integer data_unit character ( len = * ) header integer i character ( len = 255 ) png_filename double precision xvec(nvec) double precision yvec(nvec) c c Create a graphics data file. c data_filename = header // '_data.txt' call get_unit ( data_unit ) open ( unit = data_unit, file = data_filename, & status = 'replace' ) do i = 1, nvec write ( data_unit, '(2g14.6)' ) xvec(i), yvec(i) end do close ( unit = data_unit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Created graphics data file "' & // trim ( data_filename ) // '".' png_filename = header // '.png' c c Create graphics command file. c call get_unit ( command_unit ) command_filename = header // '_commands.txt' open ( unit = command_unit, file = command_filename, & status = 'replace' ) write ( command_unit, '(a)' ) '# ' // trim ( command_filename ) write ( command_unit, '(a)' ) '#' write ( command_unit, '(a)' ) '# Usage:' write ( command_unit, '(a)' ) '# gnuplot < ' & // trim ( command_filename ) write ( command_unit, '(a)' ) '#' write ( command_unit, '(a)' ) 'set term png' write ( command_unit, '(a)' ) 'set output "' & // trim ( png_filename ) // '"' write ( command_unit, '(a)' ) 'set xlabel "<--- X --->"' write ( command_unit, '(a)' ) 'set ylabel "<-- Y(X) -->"' write ( command_unit, '(a)' ) 'set title "' // header // '"' write ( command_unit, '(a)' ) 'set grid' write ( command_unit, '(a)' ) 'set style data lines' write ( command_unit, '(a)' ) 'plot "' // trim ( data_filename ) & // '" using 1:2 lw 3 linecolor rgb "blue"' close ( unit = command_unit ) write ( *, '(a)' ) ' Created command file "' & // trim ( command_filename ) // '".' return end subroutine sigmoid_poly_print ( n, a, title ) c*********************************************************************72 c cc sigmoid_poly_print() prints a polynomial in s(x). c c Discussion: c c The power sum form is: c c p(x) = a(0) + a(1) * x + ... + a(n-1) * x^(n-1) + a(n) * x^(n) c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 15 July 2015 c c Author: c c John Burkardt c c Input: c c integer N, the dimension of A. c c real ( kind = rk ) A(0:N), the polynomial coefficients. c A(0) is the constant term and c A(N) is the coefficient of X^N. c c character ( len = * ) TITLE, a title. c implicit none integer n double precision a(0:n-1) integer i double precision mag character plus_minus character ( len = * ) title write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) // ' = ' do i = 0, n - 1 if ( a(i) < 0.0D+00 ) then plus_minus = '-' else plus_minus = '+' end if mag = abs ( a(i) ) if ( mag /= 0.0D+00 ) then if ( 2 <= i ) then write ( *, & ' ( '' '', a1, g14.6, '' * s(x) ^ '', i3 )' ) & plus_minus, mag, i else if ( i == 1 ) then write ( *, ' ( '' '', a1, g14.6, '' * s(x)'' )' ) & plus_minus, mag else if ( i == 0 ) then write ( *, ' ( '' '', a1, g14.6 )' ) plus_minus, mag end if end if end do return end subroutine r8vec_linspace ( n, a, b, x ) c*********************************************************************72 c cc r8vec_linspace() creates a vector of linearly spaced values. c c Discussion: c c An R8VEC is a vector of R8's. c c 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12. c c In other words, the interval is divided into N-1 even subintervals, c and the endpoints of intervals are used as the points. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 14 March 2011 c c Author: c c John Burkardt c c Input: c c integer N, the number of entries in the vector. c c double precision A, B, the first and last entries. c c Output: c c double precision X(N), a vector of linearly spaced data. c implicit none integer n double precision a double precision b integer i double precision x(n) if ( n == 1 ) then x(1) = ( a + b ) / 2.0D+00 else do i = 1, n x(i) = ( dble ( n - i ) * a & + dble ( i - 1 ) * b ) & / dble ( n - 1 ) end do end if 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