program main c*********************************************************************72 c cc VANDERMONDE_INTERP_2D_test tests the VANDERMONDE_INTERP_2D library. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 25 September 2012 c c Author: c c John Burkardt c implicit none integer m_test_num parameter ( m_test_num = 5 ) integer j integer m integer m_test(m_test_num) integer prob integer prob_num save m_test data m_test / 1, 2, 3, 4, 8 / call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'VANDERMONDE_INTERP_2D_test:' write ( *, '(a)' ) ' Fortran77 version' write ( *, '(a)' ) ' Test VANDERMONDE_INTERP_2D.' write ( *, '(a)' ) & ' This test also needs the TEST_INTERP_2D library.' call f00_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_INTERP_2D_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine test01 ( prob, m ) c*********************************************************************72 c cc TEST01 tests VANDERMONDE_INTERP_2D_MATRIX. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 25 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 degree of interpolation. c implicit none integer m_max parameter ( m_max = 8 ) integer nd_max parameter ( nd_max = ( m_max + 1 ) * ( m_max + 2 ) / 2 ) integer ni_max parameter ( ni_max = ( m_max + 1 ) * ( m_max + 2 ) / 2 ) double precision a(nd_max,nd_max) double precision app_error double precision c(nd_max) integer i integer m integer nd integer ni integer prob double precision r8vec_norm_affine integer seed integer tmp1 integer triangle_num double precision xd(nd_max) double precision xi(ni_max) double precision yd(nd_max) double precision yi(ni_max) double precision zd(nd_max) double precision zi(ni_max) write ( *, '(a)' ) '' write ( *, '(a)' ) 'TEST01:' write ( *, '(a,i6)' ) & ' Interpolate data from TEST_INTERP_2D problem #', prob write ( *, '(a,i6)' ) & ' Create an interpolant of total degree ', m tmp1 = triangle_num ( m + 1 ) write ( *, '(a,i6)' ) ' Number of data values needed is', tmp1 nd = tmp1 seed = 123456789 call random_number ( harvest = xd(1:nd) ) call random_number ( harvest = yd(1:nd) ) call f00_f0 ( prob, nd, xd, yd, zd ) call r8vec3_print ( nd, xd, yd, zd, ' X, Y, Z data:' ) c c Compute the Vandermonde matrix. c call vandermonde_interp_2d_matrix ( nd, m, xd, yd, a ) c c Solve linear system. c call qr_solve ( nd, nd, a, zd, c ) c c #1: Does interpolant match function at data points? c ni = nd do i = 1, ni xi(i) = xd(i) yi(i) = yd(i) end do call r8poly_value_2d ( m, c, ni, xi, yi, zi ) app_error = r8vec_norm_affine ( ni, zi, zd ) / dble ( ni ) write ( *, '(a)' ) '' write ( *, '(a,g14.6)' ) & ' L2 data interpolation error = ', app_error return end subroutine r8poly_value_2d ( m, c, n, x, y, p ) c*********************************************************************72 c cc r8poly_value_2d() evaluates a polynomial in 2 variables, X and Y. c c Discussion: c c We assume the polynomial is of total degree M, and has the form: c c p(x,y) = c00 c + c10 * x + c01 * y c + c20 * x^2 + c11 * xy + c02 * y^2 c + ... c + cm0 * x^(m) + ... + c0m * y^m. 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 M, the degree of the polynomial. c c Input, double precision C(T(M+1)), the polynomial coefficients. c C(1) is the constant term. T(M+1) is the M+1-th triangular number. c The coefficients are stored consistent with the following ordering c of monomials: 1, X, Y, X^2, XY, Y^2, X^3, X^2Y, XY^2, Y^3, X^4, ... c c Input, integer N, the number of evaluation points. c c Input, double precision X(N), Y(N), the evaluation points. c c Output, double precision P(N), the value of the polynomial at the c evaluation points. c implicit none integer n double precision c(*) integer ex integer ey integer i integer j integer m double precision p(n) integer s double precision x(n) double precision y(n) do i = 1, n p(i) = 0.0D+00 end do j = 0 do s = 0, m do ex = s, 0, -1 ey = s - ex j = j + 1 do i = 1, n p(i) = p(i) + c(j) * x(i) ** ex * y(i) ** ey end do end do end do 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_norm_affine ( n, v0, v1 ) c*********************************************************************72 c cc r8vec_norm_affine() returns the affine norm of an R8VEC. c c Discussion: c c An R8VEC is a vector of R8's. c c The affine vector L2 norm is defined as: c c R8VEC_NORM_AFFINE(V0,V1) c = sqrt ( sum ( 1 <= I <= N ) ( V1(I) - V0(I) )^2 ) c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 27 October 2010 c c Author: c c John Burkardt c c Parameters: c c Input, integer N, the order of the vectors. c c Input, double precision V0(N), the base vector. c c Input, double precision V1(N), the vector whose affine norm is desired. c c Output, double precision R8VEC_NORM_AFFINE, the L2 norm of V1-V0. c implicit none integer n integer i double precision r8vec_norm_affine double precision v0(n) double precision v1(n) r8vec_norm_affine = 0.0D+00 do i = 1, n r8vec_norm_affine = r8vec_norm_affine & + ( v0(i) - v1(i) ) ** 2 end do r8vec_norm_affine = sqrt ( r8vec_norm_affine ) return end subroutine r8vec3_print ( n, a1, a2, a3, title ) c*********************************************************************72 c cc r8vec3_print() prints an R8VEC3. c c Discussion: c c An R8VEC3 is a dataset consisting of N triples of R8's, stored c as three separate vectors A1, A2, A3. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 05 September 2011 c c Author: c c John Burkardt c c Parameters: c c Input, integer N, the number of components of the vector. c c Input, double precision A1(N), A2(N), A3(N), the vectors to be printed. c c Input, character * ( * ) TITLE, a title. c implicit none integer n double precision a1(n) double precision a2(n) double precision a3(n) integer i character * ( * ) title write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) write ( *, '(a)' ) ' ' do i = 1, n write ( *, '(i8,3g14.6)' ) i, a1(i), a2(i), a3(i) end do 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