function [u,d,v]=SVDecom(A)
[m,n]=size(A);
sinflag=0;
if (m>n)
    [v1,d]=eig(A*A');
    v1=GSO(v1);
    v1=fliplr(v1);
    d1(1:n,n+1:m)=zeros(n,m-n);
    dd=fliplr(diag(d.^(.5))')'; % using diag command, the result is column vector; and fliplr command only change the column!!
    d1(1:n,1:n)=diag(dd(1:n));
    d=d1;
    for i=1:n
        if (d(i,i)~=0)
            u(:,i)=A'*v1(:,i)/d(i,i);
        else
            sinflag=1;
            u(:,i)=ones(n,1); % if singular value is zero, set the corresponding column of u all ones, then use GSO to orthogonalize
        end
    end
    utmp=GSO(u);
    if (sinflag==1)
        utmp=GSO(utmp);
    end
    d=d'; u=v1;
    v=utmp;
end
if (m<n||m==n)
    [v,d]=eig(A'*A);
    v=GSO(v);
    v=fliplr(v);
    d1(1:m,m+1:n)=zeros(m,n-m);
    dd=fliplr(diag(d.^(.5))');
    d1(1:m,1:m)=diag(dd(1:m));
    d=d1;
    for i=1:m
        if(d(i,i)~=0)
            u(:,i)=A*v(:,i)/d(i,i);
        else
            sinflag=1;
            u(:,i)=ones(m,1);  % if the singular value is zero...
        end
    end
    u=GSO(u);
    if (sinflag==1)
        u=GSO(u);
    end
end