| [nm,n,ar,ai,d,e,e2,tau]=htridi(nm,n,ar,ai,d,e,e2,tau); |
function [nm,n,ar,ai,d,e,e2,tau]=htridi(nm,n,ar,ai,d,e,e2,tau);
%***BEGIN PROLOGUE HTRIDI
%***PURPOSE Reduce a complex Hermitian matrix to a real symmetric
% tridiagonal matrix using unitary similarity
% transformations.
%***LIBRARY SLATEC (EISPACK)
%***CATEGORY D4C1B1
%***TYPE SINGLE PRECISION (HTRIDI-S)
%***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
%***AUTHOR Smith, B. T., et al.
%***DESCRIPTION
%
% This subroutine is a translation of a complex analogue of
% the ALGOL procedure TRED1, NUM. MATH. 11, 181-195(1968)
% by Martin, Reinsch, and Wilkinson.
% HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 212-226(1971).
%
% This subroutine reduces a COMPLEX HERMITIAN matrix
% to a real symmetric tridiagonal matrix using
% unitary similarity transformations.
%
% On INPUT
%
% NM must be set to the row dimension of the two-dimensional
% array parameters, AR and AI, as declared in the calling
% program dimension statement. NM is an INTEGER variable.
%
% N is the order of the matrix A=(AR,AI). N is an INTEGER
% variable. N must be less than or equal to NM.
%
% AR and AI contain the real and imaginary parts, respectively,
% of the complex Hermitian input matrix. Only the lower
% triangle of the matrix need be supplied. AR and AI are two-
% dimensional REAL arrays, dimensioned AR(NM,N) and AI(NM,N).
%
% On OUTPUT
%
% AR and AI contain some information about the unitary trans-
% formations used in the reduction in the strict lower triangle
% of AR and the full lower triangle of AI. The rest of the
% matrices are unaltered.
%
% D contains the diagonal elements of the real symmetric
% tridiagonal matrix. D is a one-dimensional REAL array,
% dimensioned D(N).
%
% E contains the subdiagonal elements of the real tridiagonal
% matrix in its last N-1 positions. E(1) is set to zero.
% E is a one-dimensional REAL array, dimensioned E(N).
%
% E2 contains the squares of the corresponding elements of E.
% E2(1) is set to zero. E2 may coincide with E if the squares
% are not needed. E2 is a one-dimensional REAL array,
% dimensioned E2(N).
%
% TAU contains further information about the transformations.
% TAU is a one-dimensional REAL array, dimensioned TAU(2,N).
%
% Calls PYTHAG(A,B) for sqrt(A**2 + B**2).
%
% Questions and comments should be directed to B. S. Garbow,
% APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
% ------------------------------------------------------------------
%
%***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
% Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
% system Routines - EISPACK Guide, Springer-Verlag,
% 1976.
%***ROUTINES CALLED PYTHAG
%***REVISION HISTORY (YYMMDD)
% 760101 DATE WRITTEN
% 890831 Modified array declarations. (WRB)
% 890831 REVISION DATE from Version 3.2
% 891214 Prologue converted to Version 4.0 format. (BAB)
% 920501 Reformatted the REFERENCES section. (WRB)
%***end PROLOGUE HTRIDI
%
persistent f fi g gi gt h hh i ii j jp1 k l scalemlv si ;
if isempty(i), i=0; end;
if isempty(j), j=0; end;
if isempty(k), k=0; end;
if isempty(l), l=0; end;
if isempty(ii), ii=0; end;
if isempty(jp1), jp1=0; end;
if isempty(gt), gt=zeros(1,2); end;
ar_shape=size(ar);ar=reshape([ar(:).',zeros(1,ceil(numel(ar)./prod([nm])).*prod([nm])-numel(ar))],nm,[]);
ai_shape=size(ai);ai=reshape([ai(:).',zeros(1,ceil(numel(ai)./prod([nm])).*prod([nm])-numel(ai))],nm,[]);
d_shape=size(d);d=reshape(d,1,[]);
e_shape=size(e);e=reshape(e,1,[]);
e2_shape=size(e2);e2=reshape(e2,1,[]);
tau_shape=size(tau);tau=reshape([tau(:).',zeros(1,ceil(numel(tau)./prod([2])).*prod([2])-numel(tau))],2,[]);
if isempty(f), f=0; end;
if isempty(g), g=0; end;
if isempty(h), h=0; end;
if isempty(fi), fi=0; end;
if isempty(gi), gi=0; end;
if isempty(hh), hh=0; end;
if isempty(si), si=0; end;
if isempty(scalemlv), scalemlv=0; end;
%
%***FIRST EXECUTABLE STATEMENT HTRIDI
tau(1,n) = 1.0e0;
tau(2,n) = 0.0e0;
%
for i = 1 : n;
d(i) = ar(i,i);
end; i = fix(n+1);
% .......... FOR I=N STEP -1 UNTIL 1 DO -- ..........
for ii = 1 : n;
gt(:)=0;
i = fix(n + 1 - ii);
l = fix(i - 1);
h = 0.0e0;
scalemlv = 0.0e0;
if( l>=1 )
% .......... SCALE ROW (ALGOL TOL THEN NOT NEEDED) ..........
for k = 1 : l;
scalemlv = scalemlv + abs(ar(i,k)) + abs(ai(i,k));
end; k = fix(l+1);
%
if( scalemlv==0.0e0 )
tau(1,l) = 1.0e0;
tau(2,l) = 0.0e0;
else;
%
for k = 1 : l;
ar(i,k) = ar(i,k)./scalemlv;
ai(i,k) = ai(i,k)./scalemlv;
h = h + ar(i,k).*ar(i,k) + ai(i,k).*ai(i,k);
end; k = fix(l+1);
%
e2(i) = scalemlv.*scalemlv.*h;
g = sqrt(h);
e(i) = scalemlv.*g;
[f ,ar(i,l),ai(i,l)]=pythag(ar(i,l),ai(i,l));
% .......... FORM NEXT DIAGONAL ELEMENT OF MATRIX T ..........
if( f==0.0e0 )
tau(1,l) = -tau(1,i);
si = tau(2,i);
ar(i,l) = g;
else;
tau(1,l) =(ai(i,l).*tau(2,i)-ar(i,l).*tau(1,i))./f;
si =(ar(i,l).*tau(2,i)+ai(i,l).*tau(1,i))./f;
h = h + f.*g;
g = 1.0e0 + g./f;
ar(i,l) = g.*ar(i,l);
ai(i,l) = g.*ai(i,l);
if( l==1 )
gt(1)=1;
end;
end;
if(gt(1)==0)
f = 0.0e0;
%
for j = 1 : l;
g = 0.0e0;
gi = 0.0e0;
% .......... FORM ELEMENT OF A*U ..........
for k = 1 : j;
g = g + ar(j,k).*ar(i,k) + ai(j,k).*ai(i,k);
gi = gi - ar(j,k).*ai(i,k) + ai(j,k).*ar(i,k);
end; k = fix(j+1);
%
jp1 = fix(j + 1);
if( l>=jp1 )
%
for k = jp1 : l;
g = g + ar(k,j).*ar(i,k) - ai(k,j).*ai(i,k);
gi = gi - ar(k,j).*ai(i,k) - ai(k,j).*ar(i,k);
end; k = fix(l+1);
end;
% .......... FORM ELEMENT OF P ..........
e(j) = g./h;
tau(2,j) = gi./h;
f = f + e(j).*ar(i,j) - tau(2,j).*ai(i,j);
end; j = fix(l+1);
%
hh = f./(h+h);
% .......... FORM REDUCED A ..........
for j = 1 : l;
f = ar(i,j);
g = e(j) - hh.*f;
e(j) = g;
fi = -ai(i,j);
gi = tau(2,j) - hh.*fi;
tau(2,j) = -gi;
%
for k = 1 : j;
ar(j,k) = ar(j,k) - f.*e(k) - g.*ar(i,k) + fi.*tau(2,k)+ gi.*ai(i,k);
ai(j,k) = ai(j,k) - f.*tau(2,k) - g.*ai(i,k) - fi.*e(k)- gi.*ar(i,k);
end; k = fix(j+1);
end; j = fix(l+1);
end;
%
for k = 1 : l;
ar(i,k) = scalemlv.*ar(i,k);
ai(i,k) = scalemlv.*ai(i,k);
end; k = fix(l+1);
%
tau(2,l) = -si;
gt(2)=1;
end;
end;
if(gt(2)==0)
e(i) = 0.0e0;
e2(i) = 0.0e0;
end;
hh = d(i);
d(i) = ar(i,i);
ar(i,i) = hh;
ai(i,i) = scalemlv.*sqrt(h);
end; ii = fix(n+1);
%
ar_shape=zeros(ar_shape);ar_shape(:)=ar(1:numel(ar_shape));ar=ar_shape;
ai_shape=zeros(ai_shape);ai_shape(:)=ai(1:numel(ai_shape));ai=ai_shape;
d_shape=zeros(d_shape);d_shape(:)=d(1:numel(d_shape));d=d_shape;
e_shape=zeros(e_shape);e_shape(:)=e(1:numel(e_shape));e=e_shape;
e2_shape=zeros(e2_shape);e2_shape(:)=e2(1:numel(e2_shape));e2=e2_shape;
tau_shape=zeros(tau_shape);tau_shape(:)=tau(1:numel(tau_shape));tau=tau_shape;
end %subroutine htridi
%DECK HVNRM
|
|