如何进行单班QR迭代?

时间:2019-06-16 10:25:27

标签: matlab

我正在尝试为Single-Shift QR迭代编写程序。我在下面编写了代码,但没有给出正确的输出。我的过程错了吗?我在课堂上记笔记,但这是我写的结果。而且我需要一直进行下去,直到某个值小于eps为止,但是由于它不起作用,所以我仅对其进行了1000次迭代。

function [R , niter] = QRiter_s(A)

    n =length(A);
    H = A;
    eps = 10^-10;

    for j = 1:n-2
        u   = H(j+1:end,j);
        u(1) = u(1) + sign(u(1))*norm(u);
        v   = u/norm(u);

        H(j+1:end,:) = H(j+1:end,:)-2*v*(v'*H(j+1:end,:));
        H(:,j+1:end) = H(:,j+1:end)-(H(:,j+1:end)*(2*v))*v';

    end

    Q = eye(n,n);
    H0 = H;
    niter = 0;

    while niter<1000
        p = H0(n,n);
        S = H0 - p*eye(n,n);

        for j = 1:n
            u = S(:,j);
            for i = 1:j-1
                u = u - dot(Q(:,i),S(:,j))/(dot(Q(:,i),Q(:,i)))*Q(:,i);
            end
            Q(:,j)=u;
        end

        for j = 1:n
            Q(:,j)=Q(:,j)/norm(Q(:,j));
        end

        R = transpose(Q)*S;

        H0 = R*Q + p*eye(n,n);

        niter = niter + 1;

    end

end

0 个答案:

没有答案