program main !*****************************************************************************80 ! !! llsq_test() tests llsq(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 15 January 2019 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'llsq_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Test llsq().' call test01 ( ) call test02 ( ) ! ! Terminate. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'LLSQ_TEST():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop 0 end subroutine test01 ( ) !*****************************************************************************80 ! !! TEST01 calls LLSQ to match 15 data values. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 07 March 2012 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: n = 15 real ( kind = rk ) a real ( kind = rk ) b real ( kind = rk ) error integer i real ( kind = rk ) :: x(n) = (/ & 1.47, 1.50, 1.52, 1.55, 1.57, & 1.60, 1.63, 1.65, 1.68, 1.70, & 1.73, 1.75, 1.78, 1.80, 1.83 /) real ( kind = rk ) :: y(n) = (/ & 52.21, 53.12, 54.48, 55.84, 57.20, & 58.57, 59.93, 61.29, 63.11, 64.47, & 66.28, 68.10, 69.92, 72.19, 74.46 /) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST01' write ( *, '(a)' ) ' LLSQ can compute the formula for a line of the form' write ( *, '(a)' ) ' y = A * x + B' write ( *, '(a)' ) ' which minimizes the RMS error to a set of N data values.' call llsq ( n, x, y, a, b ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6,a,g14.6)' ) ' Estimated relationship is y = ', a, ' * x + ', b write ( *, '(a)' ) ' Expected value is y = 61.272 * x - 39.062' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' I X Y B+A*X |error|' write ( *, '(a)' ) ' ' error = 0.0D+00 do i = 1, n write ( *, '(2x,i4,2x,f7.4,2x,f7.4,2x,f7.4,2x,f7.4)' ) & i, x(i), y(i), b + a * x(i), b + a * x(i) - y(i) error = error + ( b + a * x(i) - y(i) )**2 end do error = sqrt ( error / real ( n, kind = rk ) ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' RMS error = ', error return end subroutine test02 ( ) !*****************************************************************************80 ! !! TEST02 calls LLSQ to match 14 data values with a line y=a*x. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 15 January 2019 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: n = 14 real ( kind = rk ) a real ( kind = rk ) error integer i real ( kind = rk ) :: x(n) = (/ & 0.00D+00, 0.10D+00, 0.15D+00, 0.20D+00, 0.25D+00, & 0.30D+00, 0.35D+00, 0.40D+00, 0.45D+00, 0.50D+00, & 0.55D+00, 0.60D+00, 0.65D+00, 0.70D+00 /) real ( kind = rk ) :: y(n) = (/ & 0.0000D+00, 0.0865D+00, 0.1015D+00, 0.1106D+00, 0.1279D+00, & 0.1892D+00, 0.2695D+00, 0.2888D+00, 0.2425D+00, 0.3465D+00, & 0.3225D+00, 0.3764D+00, 0.4263D+00, 0.4562D+00 /) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST02' write ( *, '(a)' ) ' LLSQ0 can compute the formula for a line of the form' write ( *, '(a)' ) ' y = A * x' write ( *, '(a)' ) ' which minimizes the RMS error to a set of N data values.' call llsq0 ( n, x, y, a ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6,a)' ) ' Estimated relationship is y = ', a, ' * x' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' I X Y A*X |error|' write ( *, '(a)' ) ' ' error = 0.0D+00 do i = 1, n write ( *, '(2x,i4,2x,f7.4,2x,f7.4,2x,f7.4,2x,f7.4)' ) & i, x(i), y(i), a * x(i), a * x(i) - y(i) error = error + ( a * x(i) - y(i) )**2 end do error = sqrt ( error / real ( n, kind = rk ) ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' RMS error = ', error 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 ! ! Parameters: ! ! None ! implicit none integer, parameter :: rk = 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