program polynomial_conversion_test c*********************************************************************72 c cc polynomial_conversion_test() tests polynomial_conversion(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 16 April 2024 c c Author: c c John Burkardt c implicit none call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'polynomial_conversion_test():' write ( *, '(a)' ) ' Fortran77 version' write ( *, '(a)' ) ' Test polynomial_conversion().' call chebyshev_to_monomial_test ( ) call monomial_to_chebyshev_test ( ) call chebyshev_monomial_chebyshev_test ( ) call gegenbauer_to_monomial_matrix_test ( ) call legendre_to_monomial_matrix_test ( ) c c Terminate. c write ( *, '(a)' ) '' write ( *, '(a)' ) 'polynomial_conversion_test():' write ( *, '(a)' ) ' Normal end of execution.' call timestamp ( ) stop end subroutine chebyshev_monomial_chebyshev_test ( ) c*********************************************************************72 c cc chebyshev_monomial_chebyshev_test() tests accuracy. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 18 February 2024 c c Author: c c John Burkardt c implicit none integer n parameter ( n = 10 ) double precision ccoef(0:n) double precision ccoef2(0:n) double precision e double precision mcoef(0:n) double precision r8vec_diff_norm_l2 write ( *, '(a)' ) '' write ( *, '(a)' ) 'chebyshev_monomial_chebyshev_test ( )' write ( *, '(a)' ) ' Convert a polynomial from Chebyshev form' write ( *, '(a)' ) ' to monomial form and back.' call random_number ( ccoef(0:n) ) call chebyshev_to_monomial ( n, ccoef, mcoef ) call monomial_to_chebyshev ( n, mcoef, ccoef2 ) e = r8vec_diff_norm_l2 ( n, ccoef, ccoef2 ) write ( *, '(a)' ) '' write ( *, '(a,g14.6)' ) ' L2 difference = ', e return end subroutine chebyshev_to_monomial_test ( ) c*********************************************************************72 c cc chebyshev_to_monomial_test() tests chebyshev_to_monomial(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 18 February 2024 c c Author: c c John Burkardt c implicit none integer nmax parameter ( nmax = 6 ) double precision ccoef(0:nmax) integer k double precision mcoef(0:nmax) integer n write ( *, '(a)' ) '' write ( *, '(a)' ) 'chebyshev_to_monomial_test ( )' write ( *, '(a)' ) ' chebyshev_to_monomial() converts a' write ( *, '(a)' ) ' polynomial from Chebyshev form' write ( *, '(a)' ) ' to monomial form.' write ( *, '(a)' ) '' write ( *, '(10x,7(''X**'',i1,'' ''))' ) ( k, k = 0, nmax ) write ( *, '(a)' ) '' do n = 0, nmax do k = 0, n - 1 ccoef(k) = 0.0D+00 end do ccoef(n) = 1.0D+00 call chebyshev_to_monomial ( n, ccoef, mcoef ) write ( *, '(a,i1,a,f7.3,8f8.3)' ) & 'T', n, '(x) = ', ( mcoef(k), k = 0, n ) end do return end subroutine gegenbauer_to_monomial_matrix_test ( ) c*********************************************************************72 c cc gegenbauer_to_monomial_matrix_test() tests gegenbauer_to_monomial_matrix(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 16 April 2024 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 4 double precision A(0:n,0:n) double precision alpha integer i integer j write ( *, '(a)' ) '' write ( *, '(a)' ) 'gegenbauer_to_monomial_matrix_test ( )' write ( *, '(a)' ) ' gegenbauer_to_monomial_matrix() returns the' write ( *, '(a)' ) ' matrix which converts a polynomial from' write ( *, '(a)' ) ' Gegenbauer form to monomial form.' alpha = 0.5D+00 write ( *, '(a,g14.6)' ) ' alpha = ', alpha call gegenbauer_to_monomial_matrix ( n + 1, alpha, A ) write ( *, '(a)' ) '' write ( *, '(a)' ) ' A:' write ( *, '(a)' ) '' do i = 0, n do j = 0, n write ( *, '(f8.5)', advance = 'no' ) A(i,j) end do write ( *, '(a)' ) '' end do return end subroutine legendre_to_monomial_matrix_test ( ) c*********************************************************************72 c cc legendre_to_monomial_matrix_test() tests legendre_to_monomial_matrix(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 20 February 2024 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 4 double precision A(0:n,0:n) integer i integer j write ( *, '(a)' ) '' write ( *, '(a)' ) 'legendre_to_monomial_matrix_test ( )' write ( *, '(a)' ) ' legendre_to_monomial_matrix() returns the' write ( *, '(a)' ) ' matrix which converts a polynomial from' write ( *, '(a)' ) ' Legendre form to monomial form.' call legendre_to_monomial_matrix ( n + 1, A ) write ( *, '(a)' ) '' write ( *, '(a)' ) ' A:' write ( *, '(a)' ) '' do i = 0, n do j = 0, n write ( *, '(f8.5)', advance = 'no' ) A(i,j) end do write ( *, '(a)' ) '' end do return end subroutine monomial_to_chebyshev_test ( ) c*********************************************************************72 c cc monomial_to_chebyshev_test() tests monomial_to_chebyshev(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 18 February 2024 c c Author: c c John Burkardt c implicit none integer nmax parameter ( nmax = 6 ) double precision ccoef(0:nmax) integer k double precision mcoef(0:nmax) integer n write ( *, '(a)' ) '' write ( *, '(a)' ) 'monomial_to_chebyshev_test ( )' write ( *, '(a)' ) ' monomial_to_chebyshev() converts a' write ( *, '(a)' ) ' polynomial from monomial form to ' write ( *, '(a)' ) ' Chebyshev form.' write ( *, '(a)' ) '' write ( *, '(8x,7(''T'',i1,''(x) ''))' ) ( k, k = 0, nmax ) write ( *, '(a)' ) '' do n = 0 , nmax do k = 0, n - 1 mcoef(k) = 0.0D+00 end do mcoef(n) = 1.0D+00 call monomial_to_chebyshev ( n, mcoef, ccoef ) write ( *, '(a,i1,a,8f8.5)' ) & 'X**', n, ' = ', ( ccoef(k), k = 0, n ) end do return end function r8vec_diff_norm_l2 ( n, a, b ) c*********************************************************************72 c cc r8vec_diff_norm_l2() returns the L2 norm of the difference of R8VEC's. c c Discussion: c c An R8VEC is a vector of R8 values. c c The vector L2 norm is defined as: c c R8VEC_NORM_L2 = sqrt ( sum ( 1 <= I <= N ) A(I)^2 ). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 24 June 2010 c c Author: c c John Burkardt c c Input: c c integer N, the number of entries in A. c c double precision A(N), B(N), the vectors. c c Output: c c double precision R8VEC_DIFF_NORM_L2, the L2 norm of A - B. c implicit none integer n double precision a(n) double precision b(n) integer i double precision r8vec_diff_norm_l2 double precision value value = 0.0D+00 do i = 1, n value = value + ( a(i) - b(i) )**2 end do value = sqrt ( value ) r8vec_diff_norm_l2 = 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