You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dlahilb.f 6.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. *> \brief \b DLAHILB
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * SUBROUTINE DLAHILB( N, NRHS, A, LDA, X, LDX, B, LDB, WORK, INFO)
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER N, NRHS, LDA, LDX, LDB, INFO
  15. * .. Array Arguments ..
  16. * DOUBLE PRECISION A(LDA, N), X(LDX, NRHS), B(LDB, NRHS), WORK(N)
  17. * ..
  18. *
  19. *
  20. *> \par Purpose:
  21. * =============
  22. *>
  23. *> \verbatim
  24. *>
  25. *> DLAHILB generates an N by N scaled Hilbert matrix in A along with
  26. *> NRHS right-hand sides in B and solutions in X such that A*X=B.
  27. *>
  28. *> The Hilbert matrix is scaled by M = LCM(1, 2, ..., 2*N-1) so that all
  29. *> entries are integers. The right-hand sides are the first NRHS
  30. *> columns of M * the identity matrix, and the solutions are the
  31. *> first NRHS columns of the inverse Hilbert matrix.
  32. *>
  33. *> The condition number of the Hilbert matrix grows exponentially with
  34. *> its size, roughly as O(e ** (3.5*N)). Additionally, the inverse
  35. *> Hilbert matrices beyond a relatively small dimension cannot be
  36. *> generated exactly without extra precision. Precision is exhausted
  37. *> when the largest entry in the inverse Hilbert matrix is greater than
  38. *> 2 to the power of the number of bits in the fraction of the data type
  39. *> used plus one, which is 24 for single precision.
  40. *>
  41. *> In single, the generated solution is exact for N <= 6 and has
  42. *> small componentwise error for 7 <= N <= 11.
  43. *> \endverbatim
  44. *
  45. * Arguments:
  46. * ==========
  47. *
  48. *> \param[in] N
  49. *> \verbatim
  50. *> N is INTEGER
  51. *> The dimension of the matrix A.
  52. *> \endverbatim
  53. *>
  54. *> \param[in] NRHS
  55. *> \verbatim
  56. *> NRHS is INTEGER
  57. *> The requested number of right-hand sides.
  58. *> \endverbatim
  59. *>
  60. *> \param[out] A
  61. *> \verbatim
  62. *> A is DOUBLE PRECISION array, dimension (LDA, N)
  63. *> The generated scaled Hilbert matrix.
  64. *> \endverbatim
  65. *>
  66. *> \param[in] LDA
  67. *> \verbatim
  68. *> LDA is INTEGER
  69. *> The leading dimension of the array A. LDA >= N.
  70. *> \endverbatim
  71. *>
  72. *> \param[out] X
  73. *> \verbatim
  74. *> X is DOUBLE PRECISION array, dimension (LDX, NRHS)
  75. *> The generated exact solutions. Currently, the first NRHS
  76. *> columns of the inverse Hilbert matrix.
  77. *> \endverbatim
  78. *>
  79. *> \param[in] LDX
  80. *> \verbatim
  81. *> LDX is INTEGER
  82. *> The leading dimension of the array X. LDX >= N.
  83. *> \endverbatim
  84. *>
  85. *> \param[out] B
  86. *> \verbatim
  87. *> B is DOUBLE PRECISION array, dimension (LDB, NRHS)
  88. *> The generated right-hand sides. Currently, the first NRHS
  89. *> columns of LCM(1, 2, ..., 2*N-1) * the identity matrix.
  90. *> \endverbatim
  91. *>
  92. *> \param[in] LDB
  93. *> \verbatim
  94. *> LDB is INTEGER
  95. *> The leading dimension of the array B. LDB >= N.
  96. *> \endverbatim
  97. *>
  98. *> \param[out] WORK
  99. *> \verbatim
  100. *> WORK is DOUBLE PRECISION array, dimension (N)
  101. *> \endverbatim
  102. *>
  103. *> \param[out] INFO
  104. *> \verbatim
  105. *> INFO is INTEGER
  106. *> = 0: successful exit
  107. *> = 1: N is too large; the data is still generated but may not
  108. *> be not exact.
  109. *> < 0: if INFO = -i, the i-th argument had an illegal value
  110. *> \endverbatim
  111. *
  112. * Authors:
  113. * ========
  114. *
  115. *> \author Univ. of Tennessee
  116. *> \author Univ. of California Berkeley
  117. *> \author Univ. of Colorado Denver
  118. *> \author NAG Ltd.
  119. *
  120. *> \ingroup double_matgen
  121. *
  122. * =====================================================================
  123. SUBROUTINE DLAHILB( N, NRHS, A, LDA, X, LDX, B, LDB, WORK, INFO)
  124. *
  125. * -- LAPACK test routine --
  126. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  127. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  128. *
  129. * .. Scalar Arguments ..
  130. INTEGER N, NRHS, LDA, LDX, LDB, INFO
  131. * .. Array Arguments ..
  132. DOUBLE PRECISION A(LDA, N), X(LDX, NRHS), B(LDB, NRHS), WORK(N)
  133. * ..
  134. *
  135. * =====================================================================
  136. * .. Local Scalars ..
  137. INTEGER TM, TI, R
  138. INTEGER M
  139. INTEGER I, J
  140. * ..
  141. * .. Parameters ..
  142. * NMAX_EXACT the largest dimension where the generated data is
  143. * exact.
  144. * NMAX_APPROX the largest dimension where the generated data has
  145. * a small componentwise relative error.
  146. INTEGER NMAX_EXACT, NMAX_APPROX
  147. PARAMETER (NMAX_EXACT = 6, NMAX_APPROX = 11)
  148. * ..
  149. * .. External Subroutines ..
  150. EXTERNAL XERBLA
  151. * ..
  152. * .. External Functions
  153. EXTERNAL DLASET
  154. INTRINSIC DBLE
  155. * ..
  156. * .. Executable Statements ..
  157. *
  158. * Test the input arguments
  159. *
  160. INFO = 0
  161. IF (N .LT. 0 .OR. N .GT. NMAX_APPROX) THEN
  162. INFO = -1
  163. ELSE IF (NRHS .LT. 0) THEN
  164. INFO = -2
  165. ELSE IF (LDA .LT. N) THEN
  166. INFO = -4
  167. ELSE IF (LDX .LT. N) THEN
  168. INFO = -6
  169. ELSE IF (LDB .LT. N) THEN
  170. INFO = -8
  171. END IF
  172. IF (INFO .LT. 0) THEN
  173. CALL XERBLA('DLAHILB', -INFO)
  174. RETURN
  175. END IF
  176. IF (N .GT. NMAX_EXACT) THEN
  177. INFO = 1
  178. END IF
  179. *
  180. * Compute M = the LCM of the integers [1, 2*N-1]. The largest
  181. * reasonable N is small enough that integers suffice (up to N = 11).
  182. M = 1
  183. DO I = 2, (2*N-1)
  184. TM = M
  185. TI = I
  186. R = MOD(TM, TI)
  187. DO WHILE (R .NE. 0)
  188. TM = TI
  189. TI = R
  190. R = MOD(TM, TI)
  191. END DO
  192. M = (M / TI) * I
  193. END DO
  194. *
  195. * Generate the scaled Hilbert matrix in A
  196. DO J = 1, N
  197. DO I = 1, N
  198. A(I, J) = DBLE(M) / (I + J - 1)
  199. END DO
  200. END DO
  201. *
  202. * Generate matrix B as simply the first NRHS columns of M * the
  203. * identity.
  204. CALL DLASET('Full', N, NRHS, 0.0D+0, DBLE(M), B, LDB)
  205. * Generate the true solutions in X. Because B = the first NRHS
  206. * columns of M*I, the true solutions are just the first NRHS columns
  207. * of the inverse Hilbert matrix.
  208. WORK(1) = N
  209. DO J = 2, N
  210. WORK(J) = ( ( (WORK(J-1)/(J-1)) * (J-1 - N) ) /(J-1) )
  211. $ * (N +J -1)
  212. END DO
  213. *
  214. DO J = 1, NRHS
  215. DO I = 1, N
  216. X(I, J) = (WORK(I)*WORK(J)) / (I + J - 1)
  217. END DO
  218. END DO
  219. *
  220. END