Skip to content

Instantly share code, notes, and snippets.

@jxnl
Created July 2, 2016 00:51
Show Gist options
  • Save jxnl/7ff4cf1d5e743d739c3aebdb34430974 to your computer and use it in GitHub Desktop.
Save jxnl/7ff4cf1d5e743d739c3aebdb34430974 to your computer and use it in GitHub Desktop.
a3
function [Q,R]=BandQR(A, p)
[n,n]=size(A);
R=A; %Start with R=A
Q=eye(n); %Set Q as the identity matrix
for k=1:n-1
x = zeros(p+1,1);
j=min(n, k+p-1);
x = R(k:j, k);
x(1)=x(1)+norm(x);
w=x/norm(x);
u=2*R(k:j, 1:end)'*w;
R(k:j, 1:end)=R(k:j, 1:end)-w*u';
wwt = zeros(n,n);
wwt(k:j, k:j) = w * w';
Q=Q-2*Q*wwt;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment