Code covered by the BSD License  

Highlights from
slatec

from slatec by Ben Barrowes
The slatec library converted into matlab functions.

[nm,n,t,d,e,z,ierr]=figi2(nm,n,t,d,e,z,ierr);
function [nm,n,t,d,e,z,ierr]=figi2(nm,n,t,d,e,z,ierr);
%***BEGIN PROLOGUE  FIGI2
%***PURPOSE  Transforms certain real non-symmetric tridiagonal matrix
%            to symmetric tridiagonal matrix.
%***LIBRARY   SLATEC (EISPACK)
%***CATEGORY  D4C1C
%***TYPE      SINGLE PRECISION (FIGI2-S)
%***KEYWORDS  EIGENVALUES, EIGENVECTORS, EISPACK
%***AUTHOR  Smith, B. T., et al.
%***DESCRIPTION
%
%     Given a NONSYMMETRIC TRIDIAGONAL matrix such that the products
%     of corresponding pairs of off-diagonal elements are all
%     non-negative, and zero only when both factors are zero, this
%     subroutine reduces it to a SYMMETRIC TRIDIAGONAL matrix
%     using and accumulating diagonal similarity transformations.
%
%     On INPUT
%
%        NM must be set to the row dimension of the two-dimensional
%          array parameters, T and Z, as declared in the calling
%          program dimension statement.  NM is an INTEGER variable.
%
%        N is the order of the matrix T.  N is an INTEGER variable.
%          N must be less than or equal to NM.
%
%        T contains the nonsymmetric matrix.  Its subdiagonal is
%          stored in the last N-1 positions of the first column,
%          its diagonal in the N positions of the second column,
%          and its superdiagonal in the first N-1 positions of
%          the third column.  T(1,1) and T(N,3) are arbitrary.
%          T is a two-dimensional REAL array, dimensioned T(NM,3).
%
%     On OUTPUT
%
%        T is unaltered.
%
%        D contains the diagonal elements of the tridiagonal symmetric
%          matrix.  D is a one-dimensional REAL array, dimensioned D(N).
%
%        E contains the subdiagonal elements of the tridiagonal
%          symmetric matrix in its last N-1 positions.  E(1) is not set.
%          E is a one-dimensional REAL array, dimensioned E(N).
%
%        Z contains the diagonal transformation matrix produced in the
%          symmetrization.  Z is a two-dimensional REAL array,
%          dimensioned Z(NM,N).
%
%        IERR is an INTEGER flag set to
%          Zero       for normal return,
%          N+I        if T(I,1)*T(I-1,3) is negative,
%          2*N+I      if T(I,1)*T(I-1,3) is zero with one factor
%                     non-zero.  In these cases, there does not exist
%                     a symmetrizing similarity transformation which
%                     is essential for the validity of the later
%                     eigenvector computation.
%
%     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  (NONE)
%***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  FIGI2
%
persistent h i j ; 

if isempty(i), i=0; end;
if isempty(j), j=0; end;
t_orig=t;t_shape=[nm,3];t=reshape([t_orig(1:min(prod(t_shape),numel(t_orig))),zeros(1,max(0,prod(t_shape)-numel(t_orig)))],t_shape);
d_shape=size(d);d=reshape(d,1,[]);
e_shape=size(e);e=reshape(e,1,[]);
z_shape=size(z);z=reshape([z(:).',zeros(1,ceil(numel(z)./prod([nm])).*prod([nm])-numel(z))],nm,[]);
if isempty(h), h=0; end;
%
%***FIRST EXECUTABLE STATEMENT  FIGI2
ierr = 0;
%
for i = 1 : n;
%
for j = 1 : n;
z(i,j) = 0.0e0;
end; j = fix(n+1);
%
if( i==1 )
z(i,i) = 1.0e0;
else;
h = t(i,1).*t(i-1,3);
if( h<0 )
%     .......... SET ERROR -- PRODUCT OF SOME PAIR OF OFF-DIAGONAL
%                ELEMENTS IS NEGATIVE ..........
ierr = fix(n + i);
break;
elseif( h==0 ) ;
if( t(i,1)~=0.0e0 || t(i-1,3)~=0.0e0 )
%     .......... SET ERROR -- PRODUCT OF SOME PAIR OF OFF-DIAGONAL
%                ELEMENTS IS ZERO WITH ONE MEMBER NON-ZERO ..........
ierr = fix(2.*n + i);
break;
else;
e(i) = 0.0e0;
z(i,i) = 1.0e0;
end;
else;
e(i) = sqrt(h);
z(i,i) = z(i-1,i-1).*e(i)./t(i-1,3);
end;
end;
d(i) = t(i,2);
%
end;
t_orig(1:prod(t_shape))=t;t=t_orig;
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;
z_shape=zeros(z_shape);z_shape(:)=z(1:numel(z_shape));z=z_shape;
end
%DECK FIGI

Contact us at files@mathworks.com