Householder变换的matlab实现
function =Householder(x)if size(x,1)==1
x=x';
end
n=length(x);
ninf=max(abs(x));
if ninf==0
v=x;
b=0;
return;
end
x=x/ninf;
n2=dot(x(2:n),x(2:n));
v=x;
v(1)=1;
if n2==0
b=0;
else
a=sqrt(x(1)*x(1)+n2);
if x(1)<=0
v(1)=x(1)-a;
else
v(1)=-n2/(x(1)+a);
end
b=2*v(1)*v(1)/(n2+v(1)*v(1));
v=v/v(1);
end
return function =HouseholderQR(A)
=size(A);
I=diag(ones(m,1));
d=zeros(n,1);
for j=1:n
=Householder(A(j:m,j));
A(j:m,j:n)=(I(j:m,j:m)-b*v*v')*A(j:m,j:n);
d(j)=b;
if j<m
A(j+1:m,j)=v(2:m-j+1);
end;
end; 这么好的帖子,顶一下。顺便问以下2个函数的功能是一样的吧:loveliness: 感谢资源共享,又学到了东西:@)
页:
[1]