Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ODP,A,Q,R]=QRfactor(X,Y)
- i=size(X);
- j=ones(i,1);
- A=[X j];
- [m,n]=size(A);
- R=A; %Start with R=A
- Q=eye(m); %Set Q as the identity matrix
- for k=1:n
- disp("");
- disp("h=");
- disp("");
- x=zeros(m,1);
- x(1:m,1)=R(1:m,k);
- g=norm(x);
- v=x; v(k)=x(k)+g;
- disp(v);
- %Orthogonal transformation matrix that eliminates one element
- %below the diagonal of the matrix it is post-multiplying:
- s=norm(v);
- if s~=0, w=v/s; u=2*R'*w;
- R=R-w*u'; %Product HR
- Q=Q-2*Q*w*w'; %Product QR
- endif
- endfor
- disp("");
- ODP=A\Y;
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement