function i4_log_10 ( i ) !*****************************************************************************80 ! !! i4_log_10() returns the integer part of the logarithm base 10 of an I4. ! ! Discussion: ! ! I4_LOG_10 ( I ) + 1 is the number of decimal digits in I. ! ! An I4 is an integer value. ! ! Example: ! ! I I4_LOG_10 ! ----- -------- ! 0 0 ! 1 0 ! 2 0 ! 9 0 ! 10 1 ! 11 1 ! 99 1 ! 100 2 ! 101 2 ! 999 2 ! 1000 3 ! 1001 3 ! 9999 3 ! 10000 4 ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 08 June 2003 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer I, the number whose logarithm base 10 ! is desired. ! ! Output, integer I4_LOG_10, the integer part of the ! logarithm base 10 of the absolute value of X. ! implicit none integer i integer i_abs integer i4_log_10 integer ten_pow if ( i == 0 ) then i4_log_10 = 0 else i4_log_10 = 0 ten_pow = 10 i_abs = abs ( i ) do while ( ten_pow <= i_abs ) i4_log_10 = i4_log_10 + 1 ten_pow = ten_pow * 10 end do end if return end function r8_uniform_01 ( seed ) !*****************************************************************************80 ! !! R8_UNIFORM_01 returns a unit pseudorandom R8. ! ! Discussion: ! ! An R8 is a real ( kind = rk ) value. ! ! For now, the input quantity SEED is an integer variable. ! ! This routine implements the recursion ! ! seed = 16807 * seed mod ( 2^31 - 1 ) ! r8_uniform_01 = seed / ( 2^31 - 1 ) ! ! The integer arithmetic never requires more than 32 bits, ! including a sign bit. ! ! If the initial seed is 12345, then the first three computations are ! ! Input Output R8_UNIFORM_01 ! SEED SEED ! ! 12345 207482415 0.096616 ! 207482415 1790989824 0.833995 ! 1790989824 2035175616 0.947702 ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 05 July 2006 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! Paul Bratley, Bennett Fox, Linus Schrage, ! A Guide to Simulation, ! Springer Verlag, pages 201-202, 1983. ! ! Pierre L'Ecuyer, ! Random Number Generation, ! in Handbook of Simulation, ! edited by Jerry Banks, ! Wiley Interscience, page 95, 1998. ! ! Bennett Fox, ! Algorithm 647: ! Implementation and Relative Efficiency of Quasirandom ! Sequence Generators, ! ACM Transactions on Mathematical Software, ! Volume 12, Number 4, pages 362-376, 1986. ! ! Peter Lewis, Allen Goodman, James Miller ! A Pseudo-Random Number Generator for the System/360, ! IBM Systems Journal, ! Volume 8, pages 136-143, 1969. ! ! Parameters: ! ! Input/output, integer SEED, the "seed" value, which should ! NOT be 0. On output, SEED has been updated. ! ! Output, real ( kind = rk ) R8_UNIFORM_01, a new pseudorandom variate, ! strictly between 0 and 1. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: i4_huge = 2147483647 integer k real ( kind = rk ) r8_uniform_01 integer seed if ( seed == 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'R8_UNIFORM_01 - Fatal error!' write ( *, '(a)' ) ' Input value of SEED = 0.' stop 1 end if k = seed / 127773 seed = 16807 * ( seed - k * 127773 ) - k * 2836 if ( seed < 0 ) then seed = seed + i4_huge end if r8_uniform_01 = real ( seed, kind = rk ) * 4.656612875D-10 return end subroutine r8ge_print ( m, n, a, title ) !*****************************************************************************80 ! !! R8GE_PRINT prints an R8GE matrix. ! ! Discussion: ! ! The R8GE storage format is used for a general M by N matrix. A storage ! space is made for each entry. The two dimensional logical ! array can be thought of as a vector of M*N entries, starting with ! the M entries in the column 1, then the M entries in column 2 ! and so on. Considered as a vector, the entry A(I,J) is then stored ! in vector location I+(J-1)*M. ! ! R8GE storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 07 May 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer M, the number of rows of the matrix. ! M must be positive. ! ! Input, integer N, the number of columns of the matrix. ! N must be positive. ! ! Input, real ( kind = rk ) A(M,N), the R8GE matrix. ! ! Input, character ( len = * ) TITLE, a title. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer m integer n real ( kind = rk ) a(m,n) character ( len = * ) title call r8ge_print_some ( m, n, a, 1, 1, m, n, title ) return end subroutine r8ge_print_some ( m, n, a, ilo, jlo, ihi, jhi, title ) !*****************************************************************************80 ! !! R8GE_PRINT_SOME prints some of an R8GE matrix. ! ! Discussion: ! ! The R8GE storage format is used for a general M by N matrix. A storage ! space is made for each entry. The two dimensional logical ! array can be thought of as a vector of M*N entries, starting with ! the M entries in the column 1, then the M entries in column 2 ! and so on. Considered as a vector, the entry A(I,J) is then stored ! in vector location I+(J-1)*M. ! ! R8GE storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 21 March 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer M, the number of rows of the matrix. ! M must be positive. ! ! Input, integer N, the number of columns of the matrix. ! N must be positive. ! ! Input, real ( kind = rk ) A(M,N), the R8GE matrix. ! ! Input, integer ILO, JLO, IHI, JHI, the first row and ! column, and the last row and column to be printed. ! ! Input, character ( len = * ) TITLE, a title. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: incx = 5 integer m integer n real ( kind = rk ) a(m,n) character ( len = 14 ) ctemp(incx) integer i integer i2hi integer i2lo integer ihi integer ilo integer inc integer j integer j2 integer j2hi integer j2lo integer jhi integer jlo character ( len = * ) title write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) ! ! Print the columns of the matrix, in strips of 5. ! do j2lo = jlo, jhi, incx j2hi = j2lo + incx - 1 j2hi = min ( j2hi, n ) j2hi = min ( j2hi, jhi ) inc = j2hi + 1 - j2lo write ( *, '(a)' ) ' ' do j = j2lo, j2hi j2 = j + 1 - j2lo write ( ctemp(j2), '(i7,7x)' ) j end do write ( *, '('' Col: '',5a14)' ) ( ctemp(j2), j2 = 1, inc ) write ( *, '(a)' ) ' Row' write ( *, '(a)' ) ' ---' ! ! Determine the range of the rows in this strip. ! i2lo = max ( ilo, 1 ) i2hi = min ( ihi, m ) do i = i2lo, i2hi ! ! Print out (up to) 5 entries in row I, that lie in the current strip. ! do j2 = 1, inc j = j2lo - 1 + j2 write ( ctemp(j2), '(g14.6)' ) a(i,j) end do write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j2), j2 = 1, inc ) end do end do return end subroutine r8ge_random ( m, n, seed, a ) !*****************************************************************************80 ! !! R8GE_RANDOM randomizes an R8GE matrix. ! ! Discussion: ! ! The R8GE storage format is used for a general M by N matrix. A storage ! space is made for each entry. The two dimensional logical ! array can be thought of as a vector of M*N entries, starting with ! the M entries in the column 1, then the M entries in column 2 ! and so on. Considered as a vector, the entry A(I,J) is then stored ! in vector location I+(J-1)*M. ! ! R8GE storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 11 August 2004 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! Paul Bratley, Bennett Fox, Linus Schrage, ! A Guide to Simulation, ! Springer Verlag, pages 201-202, 1983. ! ! Bennett Fox, ! Algorithm 647: ! Implementation and Relative Efficiency of Quasirandom ! Sequence Generators, ! ACM Transactions on Mathematical Software, ! Volume 12, Number 4, pages 362-376, 1986. ! ! Peter Lewis, Allen Goodman, James Miller, ! A Pseudo-Random Number Generator for the System/360, ! IBM Systems Journal, ! Volume 8, pages 136-143, 1969. ! ! Parameters: ! ! Input, integer M, N, the number of rows and columns in ! the array. ! ! Input/output, integer SEED, the "seed" value, which ! should NOT be 0. On output, SEED has been updated. ! ! Output, real ( kind = rk ) A(M,N), the array. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer m integer n real ( kind = rk ) a(m,n) integer i integer, parameter :: i4_huge = 2147483647 integer j integer k integer seed do j = 1, n do i = 1, m k = seed / 127773 seed = 16807 * ( seed - k * 127773 ) - k * 2836 if ( seed < 0 ) then seed = seed + i4_huge end if a(i,j) = real ( seed, kind = rk ) * 4.656612875D-10 end do end do return end subroutine r8ge_to_r8po ( n, a, b ) !*****************************************************************************80 ! !! R8GE_TO_R8PO copies an R8GE matrix to an R8PO matrix. ! ! Discussion: ! ! The R8PO format assumes the matrix is square and symmetric; it is also ! typically assumed that the matrix is positive definite. These are not ! required here. The copied R8PO matrix simply zeros out the lower triangle ! of the R8GE matrix. ! ! The R8GE storage format is used for a general M by N matrix. A storage ! space is made for each entry. The two dimensional logical ! array can be thought of as a vector of M*N entries, starting with ! the M entries in the column 1, then the M entries in column 2 ! and so on. Considered as a vector, the entry A(I,J) is then stored ! in vector location I+(J-1)*M. ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 02 August 2015 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A(N,N), the R8PO matrix. ! ! Output, real ( kind = rk ) B(N,N), the R8GE matrix. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) real ( kind = rk ) b(n,n) integer i integer j do i = 1, n do j = 1, n if ( i <= j ) then b(i,j) = a(i,j) else b(i,j) = 0.0D+00 end if end do end do return end subroutine r8po_det ( n, a_lu, det ) !*****************************************************************************80 ! !! R8PO_DET computes the determinant of a matrix factored by R8PO_FA. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 29 July 2015 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A_LU(N,N), the LU factors from R8PO_FA. ! ! Output, real ( kind = rk ) DET, the determinant of A. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a_lu(n,n) real ( kind = rk ) det integer i det = 1.0D+00 do i = 1, n det = det * a_lu(i,i) ** 2 end do return end subroutine r8po_dif2 ( n, a ) !*****************************************************************************80 ! !! R8PO_DIF2 returns the second difference matrix in R8PO format. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 04 August 2015 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Output, real ( kind = rk ) A(N,N), the matrix. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) integer i a(1:n,1:n) = 0.0D+00 do i = 1, n a(i,i) = 2.0D+00 end do do i = 1, n - 1 a(i,i+1) = - 1.0D+00 end do return end subroutine r8po_fa ( n, a, r ) !*****************************************************************************80 ! !! R8PO_FA factors an R8PO matrix. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! The positive definite symmetric matrix A has a Cholesky factorization ! of the form: ! ! A = R' * R ! ! where R is an upper triangular matrix with positive elements on ! its diagonal. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 03 August 2015 ! ! Author: ! ! John Burkardt. ! ! Reference: ! ! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart, ! LINPACK User's Guide, ! SIAM, 1979, ! ISBN13: 978-0-898711-72-1, ! LC: QA214.L56. ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A(N,N), the matrix. ! ! Output, real ( kind = rk ) R(N,N), the Cholesky factor R. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) integer i integer info integer j integer k real ( kind = rk ) r(n,n) real ( kind = rk ) s r(1:n,1:n) = a(1:n,1:n) do j = 1, n do k = 1, j - 1 r(k,j) = ( r(k,j) - sum ( r(1:k-1,k) * r(1:k-1,j) ) ) / r(k,k) end do s = r(j,j) - sum ( r(1:j-1,j)**2 ) if ( s <= 0.0D+00 ) then info = j write ( *, '(a)' ) '' write ( *, '(a)' ) 'R8PO_FA - Fatal error!' write ( *, '(a,i4)' ) ' Factorization failed on column ', j stop 1 end if r(j,j) = sqrt ( s ) end do info = 0 ! ! Since the Cholesky factor is stored in R8GE format, be sure to ! zero out the lower triangle. ! do i = 1, n do j = 1, i - 1 r(i,j) = 0.0D+00 end do end do return end subroutine r8po_indicator ( n, a ) !*****************************************************************************80 ! !! R8PO_INDICATOR sets up an R8PO indicator matrix. ! ! Discussion: ! ! The "indicator matrix" simply has a value like I*10+J at every ! entry of a dense matrix, or at every entry of a compressed storage ! matrix for which storage is allocated. ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 11 January 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the number of rows and columns of ! the matrix. N must be positive. ! ! Output, real ( kind = rk ) A(N,N), the R8PO matrix. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) integer fac integer i integer i4_log_10 integer j fac = 10 ** ( i4_log_10 ( n ) + 1 ) do i = 1, n do j = 1, i - 1 a(i,j) = 0.0D+00 end do do j = i, n a(i,j) = real ( fac * i + j, kind = rk ) end do end do return end subroutine r8po_inverse ( n, r, b ) !*****************************************************************************80 ! !! R8PO_INVERSE computes the inverse of a matrix factored by R8PO_FA. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 03 August 2015 ! ! Author: ! ! John Burkardt. ! ! Reference: ! ! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart, ! LINPACK User's Guide, ! SIAM, 1979, ! ISBN13: 978-0-898711-72-1, ! LC: QA214.L56. ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) R(N,N), the Cholesky factor.. ! ! Output, real ( kind = rk ) B(N,N), the inverse matrix, in R8PO storage. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) b(n,n) integer j integer k real ( kind = rk ) r(n,n) real ( kind = rk ) t b(1:n,1:n) = r(1:n,1:n) ! ! Compute Inverse ( R ). ! do k = 1, n b(k,k) = 1.0D+00 / b(k,k) b(1:k-1,k) = - b(1:k-1,k) * b(k,k) do j = k + 1, n t = b(k,j) b(k,j) = 0.0D+00 b(1:k,j) = b(1:k,j) + t * b(1:k,k) end do end do ! ! Compute Inverse ( R ) * ( Inverse ( R ) )'. ! do j = 1, n do k = 1, j - 1 t = b(k,j) b(1:k,k) = b(1:k,k) + t * b(1:k,j) end do b(1:j,j) = b(1:j,j) * b(j,j) end do return end subroutine r8po_ml ( n, a_lu, x, b ) !*****************************************************************************80 ! !! R8PO_ML computes A * x = b after A has been factored by R8PO_FA. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 05 March 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A_LU(N,N), the Cholesky factor from R8PO_FA. ! ! Input, real ( kind = rk ) X(N), the vector to be multiplied by A. ! ! Output, real ( kind = rk ) B(N), the product A * x. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a_lu(n,n) real ( kind = rk ) b(n) integer i real ( kind = rk ) x(n) ! ! Compute R * x = y. ! do i = 1, n b(i) = a_lu(i,i) * x(i) + sum ( a_lu(i,i+1:n) * x(i+1:n) ) end do ! ! Compute R' * y = b. ! do i = n, 1, -1 b(i) = a_lu(i,i) * b(i) + sum ( b(1:i-1) * a_lu(1:i-1,i) ) end do return end subroutine r8po_mm ( n, a, b, c ) !*****************************************************************************80 ! !! R8PO_MM multiplies two R8PO matrices. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 18 May 2007 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrices. ! N must be positive. ! ! Input, real ( kind = rk ) A(N,N), B(N,N), the R8PO factor matrices. ! ! Output, real ( kind = rk ) C(N,N), the R8PO product matrix. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) real ( kind = rk ) aik real ( kind = rk ) b(n,n) real ( kind = rk ) bkj real ( kind = rk ) c(n,n) integer i integer j integer k c(1:n,1:n) = 0.0D+00 do i = 1, n do j = i, n do k = 1, n if ( i <= k ) then aik = a(i,k) else aik = a(k,i) end if if ( k <= j ) then bkj = b(k,j) else bkj = b(j,k) end if c(i,j) = c(i,j) + aik * bkj end do end do end do return end subroutine r8po_mv ( n, a, x, b ) !*****************************************************************************80 ! !! R8PO_MV multiplies an R8PO matrix by an R8VEC. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 01 October 2003 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A(N,N), the R8PO matrix. ! ! Input, real ( kind = rk ) X(N), the vector to be multiplied by A. ! ! Output, real ( kind = rk ) B(N), the product A * x. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) real ( kind = rk ) b(n) integer i integer j real ( kind = rk ) x(n) do i = 1, n b(i) = 0.0D+00 do j = 1, i-1 b(i) = b(i) + a(j,i) * x(j) end do do j = i, n b(i) = b(i) + a(i,j) * x(j) end do end do return end subroutine r8po_print ( n, a, title ) !*****************************************************************************80 ! !! R8PO_PRINT prints an R8PO matrix. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 02 October 2003 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A(N,N), the R8PO matrix. ! ! Input, character ( len = * ) TITLE, a title. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) character ( len = * ) title call r8po_print_some ( n, a, 1, 1, n, n, title ) return end subroutine r8po_print_some ( n, a, ilo, jlo, ihi, jhi, title ) !*****************************************************************************80 ! !! R8PO_PRINT_SOME prints some of an R8PO matrix. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 01 October 2003 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A(N,N), the R8PO matrix. ! ! Input, integer ILO, JLO, IHI, JHI, the first row and ! column, and the last row and column to be printed. ! ! Input, character ( len = * ) TITLE, a title. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: incx = 5 integer n real ( kind = rk ) a(n,n) real ( kind = rk ) aij character ( len = 14 ) ctemp(incx) integer i integer i2hi integer i2lo integer ihi integer ilo integer inc integer j integer j2 integer j2hi integer j2lo integer jhi integer jlo character ( len = * ) title write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) ! ! Print the columns of the matrix, in strips of 5. ! do j2lo = jlo, jhi, incx j2hi = j2lo + incx - 1 j2hi = min ( j2hi, n ) j2hi = min ( j2hi, jhi ) inc = j2hi + 1 - j2lo write ( *, '(a)' ) ' ' do j = j2lo, j2hi j2 = j + 1 - j2lo write ( ctemp(j2), '(i7,7x)' ) j end do write ( *, '('' Col: '',5a14)' ) ( ctemp(j2), j2 = 1, inc ) write ( *, '(a)' ) ' Row' write ( *, '(a)' ) ' ---' ! ! Determine the range of the rows in this strip. ! i2lo = max ( ilo, 1 ) i2hi = min ( ihi, n ) do i = i2lo, i2hi ! ! Print out (up to) 5 entries in row I, that lie in the current strip. ! do j2 = 1, inc j = j2lo - 1 + j2 if ( i <= j ) then aij = a(i,j) else aij = a(j,i) end if write ( ctemp(j2), '(g14.6)' ) aij end do write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j2), j2 = 1, inc ) end do end do return end subroutine r8po_random ( n, seed, a ) !*****************************************************************************80 ! !! R8PO_RANDOM randomizes an R8PO matrix. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! The matrix computed here is not simply a set of random numbers in ! the nonzero slots of the R8PO array. It is also a positive definite ! matrix. It is computed by setting a "random" upper triangular ! Cholesky factor R, and then computing A = R'*R. ! The randomness is limited by the fact that all the entries of ! R will be between 0 and 1. A truly random R is only required ! to have positive entries on the diagonal. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 12 October 2004 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! N must be positive. ! ! Input/output, integer SEED, a seed for the random ! number generator. ! ! Output, real ( kind = rk ) A(N,N), the R8PO matrix. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) real ( kind = rk ) r8_uniform_01 integer i integer j integer seed ! ! Set the whole matrix to zero. ! a(1:n,1:n) = 0.0D+00 do i = n, 1, -1 ! ! Set row I of R. ! do j = i, n a(i,j) = r8_uniform_01 ( seed ) end do ! ! Consider element J of row I, last to first. ! do j = n, i, -1 ! ! Add multiples of row I to lower elements of column J. ! a(i+1:j,j) = a(i+1:j,j) + a(i,i+1:j) * a(i,j) ! ! Reset element J. ! a(i,j) = a(i,i) * a(i,j) end do end do return end subroutine r8po_sl ( n, r, b, x ) !*****************************************************************************80 ! !! R8PO_SL solves an R8PO system factored by R8PO_FA. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 04 March 1999 ! ! Author: ! ! Original FORTRAN77 version by Dongarra, Bunch, Moler, Stewart. ! FORTRAN90 version by John Burkardt. ! ! Reference: ! ! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart, ! LINPACK User's Guide, ! SIAM, 1979, ! ISBN13: 978-0-898711-72-1, ! LC: QA214.L56. ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) R(N,N), the Cholesky factor from R8PO_FA. ! ! Input, real ( kind = rk ) B(N), the right hand side. ! ! Output, real ( kind = rk ) X(N), the solution vector. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) b(n) integer k real ( kind = rk ) r(n,n) real ( kind = rk ) x(n) x(1:n) = b(1:n) ! ! Solve R' * y = b. ! do k = 1, n x(k) = ( x(k) - sum ( x(1:k-1) * r(1:k-1,k) ) ) / r(k,k) end do ! ! Solve R * x = y. ! do k = n, 1, -1 x(k) = x(k) / r(k,k) x(1:k-1) = x(1:k-1) - r(1:k-1,k) * x(k) end do return end subroutine r8po_to_r8ge ( n, a, b ) !*****************************************************************************80 ! !! R8PO_TO_R8GE copies an R8PO matrix to an R8GE matrix. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! The R8GE storage format is used for a general M by N matrix. A storage ! space is made for each entry. The two dimensional logical ! array can be thought of as a vector of M*N entries, starting with ! the M entries in the column 1, then the M entries in column 2 ! and so on. Considered as a vector, the entry A(I,J) is then stored ! in vector location I+(J-1)*M. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 01 October 2003 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! ! Input, real ( kind = rk ) A(N,N), the R8PO matrix. ! ! Output, real ( kind = rk ) B(N,N), the R8GE matrix. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) real ( kind = rk ) b(n,n) integer i integer j do i = 1, n do j = 1, n if ( i <= j ) then b(i,j) = a(i,j) else b(i,j) = a(j,i) end if end do end do return end subroutine r8po_zeros ( n, a ) !*****************************************************************************80 ! !! R8PO_ZEROS zeroes an R8PO matrix. ! ! Discussion: ! ! The R8PO storage format is used for a symmetric positive definite ! matrix and its inverse. (The Cholesky factor of an R8PO matrix is an ! upper triangular matrix, so it will be in R8GE storage format.) ! ! Only the diagonal and upper triangle of the square array are used. ! This same storage scheme is used when the matrix is factored by ! R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle ! is set to zero. ! ! R8PO storage is used by LINPACK and LAPACK. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 01 August 2015 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the order of the matrix. ! N must be positive. ! ! Output, real ( kind = rk ) A(N,N), the R8PO matrix. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n,n) a(1:n,1:n) = 0.0D+00 return end subroutine r8ut_print ( m, n, a, title ) !*****************************************************************************80 ! !! R8UT_PRINT prints an R8UT matrix. ! ! Discussion: ! ! The R8UT storage format is used for an M by N upper triangular ! matrix. The format stores all M*N entries, even those which are zero. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 07 May 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer M, the number of rows of the matrix. ! M must be positive. ! ! Input, integer N, the number of columns of the matrix. ! N must be positive. ! ! Input, real ( kind = rk ) A(M,N), the R8UT matrix. ! ! Input, character ( len = * ) TITLE, a title. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer m integer n real ( kind = rk ) a(m,n) character ( len = * ) title call r8ut_print_some ( m, n, a, 1, 1, m, n, title ) return end subroutine r8ut_print_some ( m, n, a, ilo, jlo, ihi, jhi, title ) !*****************************************************************************80 ! !! R8UT_PRINT_SOME prints some of an R8UT matrix. ! ! Discussion: ! ! The R8UT storage format is used for an M by N upper triangular ! matrix. The format stores all M*N entries, even those which are zero. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 18 August 2015 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer M, the number of rows of the matrix. ! M must be positive. ! ! Input, integer N, the number of columns of the matrix. ! N must be positive. ! ! Input, real ( kind = rk ) A(M,N), the R8UT matrix. ! ! Input, integer ILO, JLO, IHI, JHI, the first row and ! column, and the last row and column to be printed. ! 1 <= ILO <= IHI <= M. ! 1 <= JLO <= JHI <= N. ! ! Input, character ( len = * ) TITLE, a title. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: incx = 5 integer m integer n real ( kind = rk ) a(m,n) character ( len = 14 ) ctemp(incx) integer i integer i2hi integer i2lo integer ihi integer ilo integer inc integer j integer j2 integer j2hi integer j2lo integer jhi integer jlo character ( len = * ) title write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) ! ! Print the columns of the matrix, in strips of 5. ! do j2lo = jlo, jhi, incx j2hi = j2lo + incx - 1 j2hi = min ( j2hi, n ) j2hi = min ( j2hi, jhi ) inc = j2hi + 1 - j2lo write ( *, '(a)' ) ' ' do j = j2lo, j2hi j2 = j + 1 - j2lo write ( ctemp(j2), '(i7,7x)' ) j end do write ( *, '(a,5a14)' ) ' Col: ', ( ctemp(j2), j2 = 1, inc ) write ( *, '(a)' ) ' Row' write ( *, '(a)' ) ' ---' ! ! Determine the range of the rows in this strip. ! i2lo = max ( ilo, 1 ) i2hi = min ( ihi, m ) do i = i2lo, i2hi ! ! Print out (up to) 5 entries in row I, that lie in the current strip. ! do j2 = 1, inc j = j2lo - 1 + j2 if ( j < i ) then ctemp(j2) = ' ' else write ( ctemp(j2), '(g14.6)' ) a(i,j) end if end do write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j2), j2 = 1, inc ) end do end do return end subroutine r8vec_indicator1 ( n, a ) !*****************************************************************************80 ! !! R8VEC_INDICATOR1 sets an R8VEC to the indicator vector (1,2,3,...). ! ! Discussion: ! ! An R8VEC is a vector of R8's. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 27 September 2014 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the number of elements of A. ! ! Output, real ( kind = rk ) A(N), the array. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n) integer i do i = 1, n a(i) = real ( i, kind = rk ) end do return end subroutine r8vec_print ( n, a, title ) !*****************************************************************************80 ! !! R8VEC_PRINT prints an R8VEC. ! ! Discussion: ! ! An R8VEC is a vector of R8's. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 22 August 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the number of components of the vector. ! ! Input, real ( kind = rk ) A(N), the vector to be printed. ! ! Input, character ( len = * ) TITLE, a title. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) a(n) integer i character ( len = * ) title write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) write ( *, '(a)' ) ' ' do i = 1, n write ( *, '(2x,i8,a,1x,g16.8)' ) i, ':', a(i) end do return end