LAPACK  3.5.0
LAPACK: Linear Algebra PACKage
sgebal.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine sgebal (JOB, N, A, LDA, ILO, IHI, SCALE, INFO)
 SGEBAL More...
 

Function/Subroutine Documentation

subroutine sgebal ( character  JOB,
integer  N,
real, dimension( lda, * )  A,
integer  LDA,
integer  ILO,
integer  IHI,
real, dimension( * )  SCALE,
integer  INFO 
)

SGEBAL

Download SGEBAL + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 SGEBAL balances a general real matrix A.  This involves, first,
 permuting A by a similarity transformation to isolate eigenvalues
 in the first 1 to ILO-1 and last IHI+1 to N elements on the
 diagonal; and second, applying a diagonal similarity transformation
 to rows and columns ILO to IHI to make the rows and columns as
 close in norm as possible.  Both steps are optional.

 Balancing may reduce the 1-norm of the matrix, and improve the
 accuracy of the computed eigenvalues and/or eigenvectors.
Parameters
[in]JOB
          JOB is CHARACTER*1
          Specifies the operations to be performed on A:
          = 'N':  none:  simply set ILO = 1, IHI = N, SCALE(I) = 1.0
                  for i = 1,...,N;
          = 'P':  permute only;
          = 'S':  scale only;
          = 'B':  both permute and scale.
[in]N
          N is INTEGER
          The order of the matrix A.  N >= 0.
[in,out]A
          A is REAL array, dimension (LDA,N)
          On entry, the input matrix A.
          On exit,  A is overwritten by the balanced matrix.
          If JOB = 'N', A is not referenced.
          See Further Details.
[in]LDA
          LDA is INTEGER
          The leading dimension of the array A.  LDA >= max(1,N).
[out]ILO
          ILO is INTEGER
[out]IHI
          IHI is INTEGER
          ILO and IHI are set to integers such that on exit
          A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
          If JOB = 'N' or 'S', ILO = 1 and IHI = N.
[out]SCALE
          SCALE is REAL array, dimension (N)
          Details of the permutations and scaling factors applied to
          A.  If P(j) is the index of the row and column interchanged
          with row and column j and D(j) is the scaling factor
          applied to row and column j, then
          SCALE(j) = P(j)    for j = 1,...,ILO-1
                   = D(j)    for j = ILO,...,IHI
                   = P(j)    for j = IHI+1,...,N.
          The order in which the interchanges are made is N to IHI+1,
          then 1 to ILO-1.
[out]INFO
          INFO is INTEGER
          = 0:  successful exit.
          < 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.
Date
November 2013
Further Details:
  The permutations consist of row and column interchanges which put
  the matrix in the form

             ( T1   X   Y  )
     P A P = (  0   B   Z  )
             (  0   0   T2 )

  where T1 and T2 are upper triangular matrices whose eigenvalues lie
  along the diagonal.  The column indices ILO and IHI mark the starting
  and ending columns of the submatrix B. Balancing consists of applying
  a diagonal similarity transformation inv(D) * B * D to make the
  1-norms of each row of B and its corresponding column nearly equal.
  The output matrix is

     ( T1     X*D          Y    )
     (  0  inv(D)*B*D  inv(D)*Z ).
     (  0      0           T2   )

  Information about the permutations P and the diagonal matrix D is
  returned in the vector SCALE.

  This subroutine is based on the EISPACK routine BALANC.

  Modified by Tzu-Yi Chen, Computer Science Division, University of
    California at Berkeley, USA

Definition at line 162 of file sgebal.f.

162 *
163 * -- LAPACK computational routine (version 3.5.0) --
164 * -- LAPACK is a software package provided by Univ. of Tennessee, --
165 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
166 * November 2013
167 *
168 * .. Scalar Arguments ..
169  CHARACTER job
170  INTEGER ihi, ilo, info, lda, n
171 * ..
172 * .. Array Arguments ..
173  REAL a( lda, * ), scale( * )
174 * ..
175 *
176 * =====================================================================
177 *
178 * .. Parameters ..
179  REAL zero, one
180  parameter( zero = 0.0e+0, one = 1.0e+0 )
181  REAL sclfac
182  parameter( sclfac = 2.0e+0 )
183  REAL factor
184  parameter( factor = 0.95e+0 )
185 * ..
186 * .. Local Scalars ..
187  LOGICAL noconv
188  INTEGER i, ica, iexc, ira, j, k, l, m
189  REAL c, ca, f, g, r, ra, s, sfmax1, sfmax2, sfmin1,
190  $ sfmin2
191 * ..
192 * .. External Functions ..
193  LOGICAL sisnan, lsame
194  INTEGER isamax
195  REAL slamch, snrm2
196  EXTERNAL sisnan, lsame, isamax, slamch, snrm2
197 * ..
198 * .. External Subroutines ..
199  EXTERNAL sscal, sswap, xerbla
200 * ..
201 * .. Intrinsic Functions ..
202  INTRINSIC abs, max, min
203 * ..
204 * .. Executable Statements ..
205 *
206 * Test the input parameters
207 *
208  info = 0
209  IF( .NOT.lsame( job, 'N' ) .AND. .NOT.lsame( job, 'P' ) .AND.
210  $ .NOT.lsame( job, 'S' ) .AND. .NOT.lsame( job, 'B' ) ) THEN
211  info = -1
212  ELSE IF( n.LT.0 ) THEN
213  info = -2
214  ELSE IF( lda.LT.max( 1, n ) ) THEN
215  info = -4
216  END IF
217  IF( info.NE.0 ) THEN
218  CALL xerbla( 'SGEBAL', -info )
219  RETURN
220  END IF
221 *
222  k = 1
223  l = n
224 *
225  IF( n.EQ.0 )
226  $ GO TO 210
227 *
228  IF( lsame( job, 'N' ) ) THEN
229  DO 10 i = 1, n
230  scale( i ) = one
231  10 CONTINUE
232  GO TO 210
233  END IF
234 *
235  IF( lsame( job, 'S' ) )
236  $ GO TO 120
237 *
238 * Permutation to isolate eigenvalues if possible
239 *
240  GO TO 50
241 *
242 * Row and column exchange.
243 *
244  20 CONTINUE
245  scale( m ) = j
246  IF( j.EQ.m )
247  $ GO TO 30
248 *
249  CALL sswap( l, a( 1, j ), 1, a( 1, m ), 1 )
250  CALL sswap( n-k+1, a( j, k ), lda, a( m, k ), lda )
251 *
252  30 CONTINUE
253  GO TO ( 40, 80 )iexc
254 *
255 * Search for rows isolating an eigenvalue and push them down.
256 *
257  40 CONTINUE
258  IF( l.EQ.1 )
259  $ GO TO 210
260  l = l - 1
261 *
262  50 CONTINUE
263  DO 70 j = l, 1, -1
264 *
265  DO 60 i = 1, l
266  IF( i.EQ.j )
267  $ GO TO 60
268  IF( a( j, i ).NE.zero )
269  $ GO TO 70
270  60 CONTINUE
271 *
272  m = l
273  iexc = 1
274  GO TO 20
275  70 CONTINUE
276 *
277  GO TO 90
278 *
279 * Search for columns isolating an eigenvalue and push them left.
280 *
281  80 CONTINUE
282  k = k + 1
283 *
284  90 CONTINUE
285  DO 110 j = k, l
286 *
287  DO 100 i = k, l
288  IF( i.EQ.j )
289  $ GO TO 100
290  IF( a( i, j ).NE.zero )
291  $ GO TO 110
292  100 CONTINUE
293 *
294  m = k
295  iexc = 2
296  GO TO 20
297  110 CONTINUE
298 *
299  120 CONTINUE
300  DO 130 i = k, l
301  scale( i ) = one
302  130 CONTINUE
303 *
304  IF( lsame( job, 'P' ) )
305  $ GO TO 210
306 *
307 * Balance the submatrix in rows K to L.
308 *
309 * Iterative loop for norm reduction
310 *
311  sfmin1 = slamch( 'S' ) / slamch( 'P' )
312  sfmax1 = one / sfmin1
313  sfmin2 = sfmin1*sclfac
314  sfmax2 = one / sfmin2
315  140 CONTINUE
316  noconv = .false.
317 *
318  DO 200 i = k, l
319 *
320  c = snrm2( l-k+1, a( k, i ), 1 )
321  r = snrm2( l-k+1, a( i, k ), lda )
322  ica = isamax( l, a( 1, i ), 1 )
323  ca = abs( a( ica, i ) )
324  ira = isamax( n-k+1, a( i, k ), lda )
325  ra = abs( a( i, ira+k-1 ) )
326 *
327 * Guard against zero C or R due to underflow.
328 *
329  IF( c.EQ.zero .OR. r.EQ.zero )
330  $ GO TO 200
331  g = r / sclfac
332  f = one
333  s = c + r
334  160 CONTINUE
335  IF( c.GE.g .OR. max( f, c, ca ).GE.sfmax2 .OR.
336  $ min( r, g, ra ).LE.sfmin2 )GO TO 170
337  f = f*sclfac
338  c = c*sclfac
339  ca = ca*sclfac
340  r = r / sclfac
341  g = g / sclfac
342  ra = ra / sclfac
343  GO TO 160
344 *
345  170 CONTINUE
346  g = c / sclfac
347  180 CONTINUE
348  IF( g.LT.r .OR. max( r, ra ).GE.sfmax2 .OR.
349  $ min( f, c, g, ca ).LE.sfmin2 )GO TO 190
350  IF( sisnan( c+f+ca+r+g+ra ) ) THEN
351 *
352 * Exit if NaN to avoid infinite loop
353 *
354  info = -3
355  CALL xerbla( 'SGEBAL', -info )
356  RETURN
357  END IF
358  f = f / sclfac
359  c = c / sclfac
360  g = g / sclfac
361  ca = ca / sclfac
362  r = r*sclfac
363  ra = ra*sclfac
364  GO TO 180
365 *
366 * Now balance.
367 *
368  190 CONTINUE
369  IF( ( c+r ).GE.factor*s )
370  $ GO TO 200
371  IF( f.LT.one .AND. scale( i ).LT.one ) THEN
372  IF( f*scale( i ).LE.sfmin1 )
373  $ GO TO 200
374  END IF
375  IF( f.GT.one .AND. scale( i ).GT.one ) THEN
376  IF( scale( i ).GE.sfmax1 / f )
377  $ GO TO 200
378  END IF
379  g = one / f
380  scale( i ) = scale( i )*f
381  noconv = .true.
382 *
383  CALL sscal( n-k+1, g, a( i, k ), lda )
384  CALL sscal( l, f, a( 1, i ), 1 )
385 *
386  200 CONTINUE
387 *
388  IF( noconv )
389  $ GO TO 140
390 *
391  210 CONTINUE
392  ilo = k
393  ihi = l
394 *
395  RETURN
396 *
397 * End of SGEBAL
398 *
subroutine sswap(N, SX, INCX, SY, INCY)
SSWAP
Definition: sswap.f:53
integer function isamax(N, SX, INCX)
ISAMAX
Definition: isamax.f:53
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:69
real function snrm2(N, X, INCX)
SNRM2
Definition: snrm2.f:56
logical function sisnan(SIN)
SISNAN tests input for NaN.
Definition: sisnan.f:61
subroutine sscal(N, SA, SX, INCX)
SSCAL
Definition: sscal.f:55

Here is the call graph for this function:

Here is the caller graph for this function: