%
%  function_Householder_tridiagonal_alt.m  ver 1.0  September 8, 2012
%
function[Ktridiagonal]=function_Householder_tridiagonal_alt(Kstandard)
%
%
%% tic
%
%
n=max(size(Kstandard));
%
IM=eye(n);
Q=IM;
%
A=Kstandard;
%
iflag=1;
ims=2;
%
if(iflag==1)
    for ijk=1:n-2
%
        out1=sprintf(' step %d \n',ijk);
%        disp(out1);
        clear P;
        clear r;
        sum=0;
%
        for j=ijk+1:n
            sum=sum+A(ijk,j)^2;
        end
        alpha=sqrt(sum);
%%        out1=sprintf('ijk=%d alpha= %8.4g ',ijk,alpha);
%%        disp(out1);   
%
        v(1:ijk)=0;
        ccc=1+ (A(ijk,ijk+1)/alpha);
        v(ijk+1)=sqrt(0.5*ccc);
        if(abs(ccc)<1.0e-20)
            out1=sprintf('\n Warning:  ccc=%8.5g \n',ccc);
%           disp(out1);
        end
        for j=ijk+2:n
            v(j)=A(ijk,j)/(2*alpha*v(ijk+1));
        end
        v;
%
%%        P=IM-2*(v'*v)
%%        K=P*K*P
%
        if(ims==1)
            P=IM-2*(v'*v);
            Q=Q*P;
        end
%   
        u=sqrt(2)*v';
        H=0.5*norm(u)^2;
%        
        p=A*u/H;
        k=u'*p/(2*H);
        q=p-k*u;
        A=A-q*u'-u*q';
%
    end
    tol=max(max(abs(A)))*1.0e-10;
    for i=1:n
        for j=1:n
            if(abs(A(i,j))<tol && i~=j)
                A(i,j)=0;
            end
        end
    end
    A;
    clear K;
    K=A;
else
    K;
end
%% toc
%
%
Ktridiagonal=K;