LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ dlahilb()

subroutine dlahilb ( integer n,
integer nrhs,
double precision, dimension(lda, n) a,
integer lda,
double precision, dimension(ldx, nrhs) x,
integer ldx,
double precision, dimension(ldb, nrhs) b,
integer ldb,
double precision, dimension(n) work,
integer info )

DLAHILB

Purpose:
!>
!> DLAHILB generates an N by N scaled Hilbert matrix in A along with
!> NRHS right-hand sides in B and solutions in X such that A*X=B.
!>
!> The Hilbert matrix is scaled by M = LCM(1, 2, ..., 2*N-1) so that all
!> entries are integers.  The right-hand sides are the first NRHS
!> columns of M * the identity matrix, and the solutions are the
!> first NRHS columns of the inverse Hilbert matrix.
!>
!> The condition number of the Hilbert matrix grows exponentially with
!> its size, roughly as O(e ** (3.5*N)).  Additionally, the inverse
!> Hilbert matrices beyond a relatively small dimension cannot be
!> generated exactly without extra precision.  Precision is exhausted
!> when the largest entry in the inverse Hilbert matrix is greater than
!> 2 to the power of the number of bits in the fraction of the data type
!> used plus one, which is 24 for single precision.
!>
!> In single, the generated solution is exact for N <= 6 and has
!> small componentwise error for 7 <= N <= 11.
!> 
Parameters
[in]N
!>          N is INTEGER
!>          The dimension of the matrix A.
!> 
[in]NRHS
!>          NRHS is INTEGER
!>          The requested number of right-hand sides.
!> 
[out]A
!>          A is DOUBLE PRECISION array, dimension (LDA, N)
!>          The generated scaled Hilbert matrix.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A.  LDA >= N.
!> 
[out]X
!>          X is DOUBLE PRECISION array, dimension (LDX, NRHS)
!>          The generated exact solutions.  Currently, the first NRHS
!>          columns of the inverse Hilbert matrix.
!> 
[in]LDX
!>          LDX is INTEGER
!>          The leading dimension of the array X.  LDX >= N.
!> 
[out]B
!>          B is DOUBLE PRECISION array, dimension (LDB, NRHS)
!>          The generated right-hand sides.  Currently, the first NRHS
!>          columns of LCM(1, 2, ..., 2*N-1) * the identity matrix.
!> 
[in]LDB
!>          LDB is INTEGER
!>          The leading dimension of the array B.  LDB >= N.
!> 
[out]WORK
!>          WORK is DOUBLE PRECISION array, dimension (N)
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0: successful exit
!>          = 1: N is too large; the data is still generated but may not
!>               be not exact.
!>          < 0: if INFO = -i, the i-th argument had an illegal value
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 123 of file dlahilb.f.

125*
126* -- LAPACK test routine --
127* -- LAPACK is a software package provided by Univ. of Tennessee, --
128* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
129*
130* .. Scalar Arguments ..
131 INTEGER N, NRHS, LDA, LDX, LDB, INFO
132* .. Array Arguments ..
133 DOUBLE PRECISION A(LDA, N), X(LDX, NRHS), B(LDB, NRHS), WORK(N)
134* ..
135*
136* =====================================================================
137* .. Local Scalars ..
138 INTEGER TM, TI, R
139 INTEGER M
140 INTEGER I, J
141* ..
142* .. Parameters ..
143* NMAX_EXACT the largest dimension where the generated data is
144* exact.
145* NMAX_APPROX the largest dimension where the generated data has
146* a small componentwise relative error.
147 INTEGER NMAX_EXACT, NMAX_APPROX
148 parameter(nmax_exact = 6, nmax_approx = 11)
149* ..
150* .. External Subroutines ..
151 EXTERNAL xerbla
152* ..
153* .. External Functions
154 EXTERNAL dlaset
155 INTRINSIC dble
156* ..
157* .. Executable Statements ..
158*
159* Test the input arguments
160*
161 info = 0
162 IF (n .LT. 0 .OR. n .GT. nmax_approx) THEN
163 info = -1
164 ELSE IF (nrhs .LT. 0) THEN
165 info = -2
166 ELSE IF (lda .LT. n) THEN
167 info = -4
168 ELSE IF (ldx .LT. n) THEN
169 info = -6
170 ELSE IF (ldb .LT. n) THEN
171 info = -8
172 END IF
173 IF (info .LT. 0) THEN
174 CALL xerbla('DLAHILB', -info)
175 RETURN
176 END IF
177 IF (n .GT. nmax_exact) THEN
178 info = 1
179 END IF
180*
181* Compute M = the LCM of the integers [1, 2*N-1]. The largest
182* reasonable N is small enough that integers suffice (up to N = 11).
183 m = 1
184 DO i = 2, (2*n-1)
185 tm = m
186 ti = i
187 r = mod(tm, ti)
188 DO WHILE (r .NE. 0)
189 tm = ti
190 ti = r
191 r = mod(tm, ti)
192 END DO
193 m = (m / ti) * i
194 END DO
195*
196* Generate the scaled Hilbert matrix in A
197 DO j = 1, n
198 DO i = 1, n
199 a(i, j) = dble(m) / (i + j - 1)
200 END DO
201 END DO
202*
203* Generate matrix B as simply the first NRHS columns of M * the
204* identity.
205 CALL dlaset('Full', n, nrhs, 0.0d+0, dble(m), b, ldb)
206
207* Generate the true solutions in X. Because B = the first NRHS
208* columns of M*I, the true solutions are just the first NRHS columns
209* of the inverse Hilbert matrix.
210 work(1) = n
211 DO j = 2, n
212 work(j) = ( ( (work(j-1)/(j-1)) * (j-1 - n) ) /(j-1) )
213 $ * (n +j -1)
214 END DO
215*
216 DO j = 1, nrhs
217 DO i = 1, n
218 x(i, j) = (work(i)*work(j)) / (i + j - 1)
219 END DO
220 END DO
221*
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine dlaset(uplo, m, n, alpha, beta, a, lda)
DLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition dlaset.f:108
Here is the call graph for this function: