# ?lag2

Computes the eigenvalues of a 2-by-2 generalized eigenvalue problem, with scaling as necessary to avoid over-/underflow.

## Syntax

call slag2( a, lda, b, ldb, safmin, scale1, scale2, wr1, wr2, wi )

call dlag2( a, lda, b, ldb, safmin, scale1, scale2, wr1, wr2, wi )

## Description

This routine computes the eigenvalues of a 2 x 2 generalized eigenvalue problem A - w *B, with scaling as necessary to avoid over-/underflow. The scaling factor, s, results in a modified eigenvalue equation

`s*A - w*B` ,

where s is a non-negative scaling factor chosen so that w, w*B, and s*A do not overflow and, if possible, do not underflow, either.

## Input Parameters

a, b

  REAL for slag2

  DOUBLE PRECISION for dlag2

  Arrays:

  `a(lda,2)` contains, on entry, the 2 x 2 matrix A. It is assumed that its 1-norm is less than `1/safmin`. Entries less than `sqrt(safmin)*norm(A)` are subject to being treated as zero.

  b(ldb,2) contains, on entry, the 2 x 2 upper triangular matrix B. It is assumed that the one-norm of B is less than 1/safmin. The diagonals should be at least sqrt(safmin) times the largest element of B (in absolute value); if a diagonal is smaller than that, then `+/- sqrt(safmin)` will be used instead of that diagonal.

lda

  INTEGER. The first dimension of a; `lda ≥ 2`.

ldb

  INTEGER. The first dimension of b; `ldb ≥ 2`.

safmin

  REAL for slag2;

  DOUBLE PRECISION for dlag2.

  The smallest positive number such that `1/safmin` does not overflow. (This should always be ?lamch('S') - it is an argument in order to avoid having to call ?lamch frequently.)

## Output Parameters

scale1

  REAL for slag2;

  DOUBLE PRECISION for dlag2.

  A scaling factor used to avoid over-/underflow in the eigenvalue equation which defines the first eigenvalue. If the eigenvalues are complex, then the eigenvalues are `(wr1 +/- wii)/scale1` (which may lie outside the exponent range of the machine), `scale1=scale2`, and scale1 will always be positive.

  If the eigenvalues are real, then the first (real) eigenvalue is `wr1/scale1`, but this may overflow or underflow, and in fact, scale1 may be zero or less than the underflow threshhold if the exact eigenvalue is sufficiently large.

scale2

  REAL for slag2;

  DOUBLE PRECISION for dlag2.

  A scaling factor used to avoid over-/underflow in the eigenvalue equation which defines the second eigenvalue. If the eigenvalues are complex, then `scale2=scale1`. If the eigenvalues are real, then the second (real) eigenvalue is `wr2/scale2`, but this may overflow or underflow, and in fact, scale2 may be zero or less than the underflow threshold if the exact eigenvalue is sufficiently large.

wr1

  REAL for slag2;

  DOUBLE PRECISION for dlag2.

  If the eigenvalue is real, then wr1 is scale1 times the eigenvalue closest to the (2,2) element of A*`inv(B)`.

  If the eigenvalue is complex, then `wr1=wr2` is scale1 times the real part of the eigenvalues.

wr2

  REAL for slag2;

  DOUBLE PRECISION for dlag2.

  If the eigenvalue is real, then wr2 is scale2 times the other eigenvalue. If the eigenvalue is complex, then `wr1=wr2` is scale1 times the real part of the eigenvalues.

wi

  REAL for slag2;

  DOUBLE PRECISION for dlag2.

  If the eigenvalue is real, then wi is zero. If the eigenvalue is complex, then wi is scale1 times the imaginary part of the eigenvalues. wi will always be non-negative.

Parent topic: Auxiliary Routines