matlab任意生成一个实矩阵 用household变换成下三角矩阵(在线等)

1个回答

  • function [Q,R]=Householder(A)

    [m,n]=size(A); %要求m>=n;

    V=zeros(m);

    Q=eye(m);

    R=zeros(m,n);

    a=zeros(m,n);

    for k=1:n

    P=eye(m);

    I=eye(n-k+1);

    x=A(1:n-k+1,n-k+1);

    e=zeros(n-k+1,1);

    e(n-k+1,1)=1;

    V(1:n-k+1,k)= sign(x(n-k+1))*norm(x)*e+x;

    V(1:n-k+1,k)=V(1:n-k+1,k)/norm(V(1:n-k+1,k));

    F=I-2*V(1:n-k+1,k)*V(1:n-k+1,k)';

    P(1:n-k+1,1:n-k+1)=F;

    Q=Q*P; A(1:n-k+1,1:n-k+1)=A(1:n-k+1,1:n-k+1)-2*V(1:n-k+1,k)*(V(1:n-k+1,k))'*A(1:n-k+1,1:n-k+1);

    end

    R=A;

    致班长~坐等继续追加60分╮(╯▽╰)╭