UNIT

Normalizes the columns of a matrix so each has Euclidean length of value one.

Function Return Value

Matrix containing the normalized values of A . The output function value is an array of the same type and kind as A, where each column of each rank-2 principal section has Euclidean length of value one (Output)

Required Argument

A — Matrix to be normalized. The argument must be a rank-2 or rank-3 array of type single, double, complex, or double complex. (Input)

FORTRAN 90 Interface

UNIT (A)

Description

Normalizes the columns of a rank-2 or rank-3 array so each has Euclidean length of value one.

This function uses a rank-2 Euclidean length subroutine to compute the lengths of the nonzero columns, which are then normalized to have lengths of value one. The subroutine carefully avoids overflow or damaging underflow by rescaling the sums of squares as required.

Example (operator_ex28.f90)

 

use linear_operators

 

implicit none

 

! This is the equivalent of Example 4 (using operators) for LIN_EIG_SELF.

 

integer, parameter :: n=64

real(kind(1e0)), parameter :: one=1d0

real(kind(1e0)), dimension(n,n) :: A, B, C, D(n), lambda(n), &

S(n), vb_d, X, res

 

! Generate random self-adjoint matrices.

A = rand(A); A = A + .t.A

B = rand(B); B = B + .t.B

 

! Add a scalar matrix so B is positive definite.

B = B + norm(B)*EYE(n)

 

! Get the eigenvalues and eigenvectors for B.

S = EIG(B,V=vb_d)

 

! For full rank problems, convert to an ordinary self-adjoint

! problem. (All of these examples are full rank.)

if (S(n) > epsilon(one)) then

D = one/sqrt(S)

C = diag(D) .x. (vb_d .tx. A .x. vb_d) .x. diag(D)

C = (C + .t.C)/2

 

! Get the eigenvalues and eigenvectors for C.

lambda = EIG(C,v=X)

 

! Compute and normalize the generalized eigenvectors.

X = UNIT(vb_d .x. diag(D) .x. X)

res = (A .x. X) - (B .x. X .x. diag(lambda))

 

! Check the results.

if(norm(res)/(norm(A)+norm(B)) <= &

sqrt(epsilon(one))) then

write (*,*) 'Example 4 for LIN_EIG_SELF (operators) is correct.'

end if

 

end if

 

end