SHARE
TWEET

Untitled

a guest Dec 14th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top