program main c*********************************************************************72 c cc vandermonde_approx_1d_test() tests vandermonde_approx_1d(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 23 September 2012 c c Author: c c John Burkardt c implicit none integer m_test_num parameter ( m_test_num = 8 ) integer j integer m integer m_test(m_test_num) integer prob integer prob_num save m_test data m_test / 0, 1, 2, 3, 4, 5, 9, 12 / call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'vandermonde_approx_1d_test)_:' write ( *, '(a)' ) ' FORTRAN77 version' write ( *, '(a)' ) ' Test vandermonde_approx_1d().' write ( *, '(a)' ) ' The QR_SOLVE library is needed.' write ( *, '(a)' ) ' The TEST_INTERP library is needed.' call p00_prob_num ( prob_num ) do prob = 1, prob_num do j = 1, m_test_num m = m_test(j) call test01 ( prob, m ) end do end do c c Terminate. c write ( *, '(a)' ) '' write ( *, '(a)' ) 'vandermonde_approx_1d_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine test01 ( prob, m ) c*********************************************************************72 c cc TEST01 tests VANDERMONDE_APPROX_1D_MATRIX. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 23 September 2012 c c Author: c c John Burkardt c c Parameters: c c Input, integer PROB, the problem number. c c Input, integer M, the polynomial degree. c implicit none integer m integer nd_max parameter ( nd_max = 49 ) integer ni_max parameter ( ni_max = 501 ) double precision a(nd_max,0:m) double precision app_error double precision c(0:m) integer i double precision ld double precision li integer nd integer ni integer prob double precision r8vec_max double precision r8vec_min double precision r8vec_norm_affine double precision xd(nd_max) double precision xi(ni_max) double precision xmax double precision xmin double precision xy(2,nd_max) double precision yd(nd_max) double precision yi(ni_max) double precision ymax double precision ymin write ( *, '(a)' ) '' write ( *, '(a)' ) 'TEST01:' write ( *, '(a,i4)' ) & ' Approximate data from TEST_INTERP problem #', prob call p00_data_num ( prob, nd ) write ( *, '(a,i4)' ) ' Number of data points = ', nd call p00_data ( prob, 2, nd, xy ) if ( m .eq. 0 ) then call r8mat_transpose_print ( 2, nd, xy, ' Data array:' ) end if do i = 1, nd xd(i) = xy(1,i) yd(i) = xy(2,i) end do c c Compute the Vandermonde matrix. c write ( *, '(a,i4)' ) & ' Using polynomial approximant of degree ', m call vandermonde_approx_1d_matrix ( nd, m, xd, a ) c c Solve linear system. c call qr_solve ( nd, m + 1, a, yd, c ) c c #1: Does approximant match function at data points? c ni = nd do i = 1, ni xi(i) = xd(i) end do call r8poly_values_horner ( m, c, ni, xi, yi ) app_error = r8vec_norm_affine ( ni, yi, yd ) / dble ( ni ) write ( *, '(a)' ) '' write ( *, '(a,g14.6)' ) & ' L2 data approximation error = ', app_error c c #2: Compare estimated curve length to piecewise linear (minimal) curve length. c Assume data is sorted, and normalize X and Y dimensions by (XMAX-XMIN) and c (YMAX-YMIN). c xmax = r8vec_max ( nd, xd ) xmin = r8vec_min ( nd, xd ) ymax = r8vec_max ( nd, yd ) ymin = r8vec_min ( nd, yd ) ni = 501 call r8vec_linspace ( ni, xmin, xmax, xi ) call r8poly_values_horner ( m, c, ni, xi, yi ) ld = 0.0D+00 do i = 1, nd - 1 ld = ld + sqrt & ( ( ( xd(i+1) - xd(i) ) / ( xmax - xmin ) ) ** 2 & + ( ( yd(i+1) - yd(i) ) / ( ymax - ymin ) ) ** 2 ) end do li = 0.0D+00 do i = 1, ni - 1 li = li + sqrt & ( ( ( xi(i+1) - xi(i) ) / ( xmax - xmin ) ) ** 2 & + ( ( yi(i+1) - yi(i) ) / ( ymax - ymin ) ) ** 2 ) end do write ( *, '(a)' ) '' write ( *, '(a,g14.6)' ) & ' Normalized length of piecewise linear interpolant = ', ld write ( *, '(a,g14.6)' ) & ' Normalized length of polynomial approximant = ', li return end subroutine r8mat_transpose_print ( m, n, a, title ) c*********************************************************************72 c cc r8mat_transpose_print() prints an R8MAT, transposed. c c Discussion: c c An R8MAT is an array of R8's. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 April 2008 c c Author: c c John Burkardt c c Parameters: c c Input, integer M, N, the number of rows and columns. c c Input, double precision A(M,N), an M by N matrix to be printed. c c Input, character*(*) TITLE, a title. c implicit none integer m integer n double precision a(m,n) character*(*) title call r8mat_transpose_print_some ( m, n, a, 1, 1, m, n, title ) return end subroutine r8mat_transpose_print_some ( m, n, a, ilo, jlo, ihi, & jhi, title ) c*********************************************************************72 c cc r8mat_transpose_print_some() prints some of an R8MAT transposed. c c Discussion: c c An R8MAT is an array of R8's. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 April 2008 c c Author: c c John Burkardt c c Parameters: c c Input, integer M, N, the number of rows and columns. c c Input, double precision A(M,N), an M by N matrix to be printed. c c Input, integer ILO, JLO, the first row and column to print. c c Input, integer IHI, JHI, the last row and column to print. c c Input, character * ( * ) TITLE, a title. c implicit none integer incx parameter ( incx = 5 ) integer m integer n double precision a(m,n) character * ( 14 ) ctemp(incx) integer i integer i2 integer i2hi integer i2lo integer ihi integer ilo integer inc integer j integer j2hi integer j2lo integer jhi integer jlo character * ( * ) title write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) if ( m .le. 0 .or. n .le. 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' (None)' return end if do i2lo = max ( ilo, 1 ), min ( ihi, m ), incx i2hi = i2lo + incx - 1 i2hi = min ( i2hi, m ) i2hi = min ( i2hi, ihi ) inc = i2hi + 1 - i2lo write ( *, '(a)' ) ' ' do i = i2lo, i2hi i2 = i + 1 - i2lo write ( ctemp(i2), '(i8,6x)') i end do write ( *, '('' Row'',5a14)' ) ctemp(1:inc) write ( *, '(a)' ) ' Col' j2lo = max ( jlo, 1 ) j2hi = min ( jhi, n ) do j = j2lo, j2hi do i2 = 1, inc i = i2lo - 1 + i2 write ( ctemp(i2), '(g14.6)' ) a(i,j) end do write ( *, '(2x,i8,a,5a14)' ) j, ':', ( ctemp(i), i = 1, inc ) end do end do return end subroutine r8poly_values_horner ( m, c, n, x, p ) c*********************************************************************72 c cc r8poly_values_horner() evaluates a polynomial using Horner's method. c c Discussion: c c The polynomial c c p(x) = c0 + c1 * x + c2 * x^2 + ... + cm * x^m c c is to be evaluated at the vector of values X. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 21 September 2012 c c Author: c c John Burkardt c c Parameters: c c Input, integer M, the degree. c c Input, double precision C(0:M), the polynomial coefficients. c C(I) is the coefficient of X^I. c c Input, integer N, the number of evaluation points. c c Input, double precision X(N), the evaluation points. c c Output, double precision P(N), the polynomial values. c implicit none integer m integer n double precision c(0:m) integer i integer j double precision p(n) double precision x(n) do j = 1, n p(j) = c(m) end do do i = m - 1, 0, -1 do j = 1, n p(j) = p(j) * x(j) + c(i) end do 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 Parameters: c c Input, integer N, the number of entries in the vector. c c Input, double precision A, B, the first and last entries. c c Output, 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 .eq. 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 function r8vec_max ( n, a ) c*********************************************************************72 c cc r8vec_max() returns the maximum value in an R8VEC. c c Discussion: c c An R8VEC is a vector of R8's. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 12 May 2014 c c Author: c c John Burkardt c c Parameters: c c Input, integer N, the number of entries in the array. c c Input, double precision A(N), the array. c c Output, double precision R8VEC_MAX, the value of the largest entry. c implicit none integer n double precision a(n) integer i double precision r8_huge parameter ( r8_huge = 1.79769313486231571D+308 ) double precision r8vec_max double precision value value = - r8_huge do i = 1, n value = max ( value, a(i) ) end do r8vec_max = value return end function r8vec_min ( n, a ) c*********************************************************************72 c cc r8vec_min() returns the minimum value in an R8VEC. c c Discussion: c c An R8VEC is a vector of R8's. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 18 January 2015 c c Author: c c John Burkardt c c Parameters: c c Input, integer N, the number of entries in the array. c c Input, double precision A(N), the array. c c Output, double precision R8VEC_MIN, the value of the smallest entry. c implicit none integer n double precision a(n) integer i double precision r8_huge parameter ( r8_huge = 1.79769313486231571D+308 ) double precision r8vec_min double precision value value = r8_huge do i = 1, n value = min ( value, a(i) ) end do r8vec_min = value 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