Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. function [ODP,A,Q,R]=QRfactor(X,Y)
  2. i=size(X);
  3. j=ones(i,1);
  4. A=[X j];
  5. [m,n]=size(A);
  6. R=A; %Start with R=A
  7. Q=eye(m); %Set Q as the identity matrix
  8. for k=1:n
  9. disp("");
  10. disp("h=");
  11. disp("");
  12. x=zeros(m,1);
  13. x(1:m,1)=R(1:m,k);
  14. g=norm(x);
  15. v=x; v(k)=x(k)+g;
  16. disp(v);
  17. %Orthogonal transformation matrix that eliminates one element
  18. %below the diagonal of the matrix it is post-multiplying:
  19. s=norm(v);
  20. if s~=0, w=v/s; u=2*R'*w;
  21. R=R-w*u'; %Product HR
  22. Q=Q-2*Q*w*w'; %Product QR
  23. endif
  24. endfor
  25. disp("");
  26. ODP=A\Y;
  27. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement