Advertisement
STANAANDREY

gram-sch orto

Mar 26th, 2023 (edited)
1,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.39 KB | None | 0 0
  1. A=[2 1;1 -1;2 1];
  2. [Q, R] = gram_schmidt(A)
  3.  
  4.  
  5.  
  6. function [Q, R] = gram_schmidt(A)
  7.  
  8.     [m, n] = size(A);
  9.     Q = zeros(m, n);
  10.     R = zeros(n, n);
  11.    
  12.     for j = 1:n
  13.         v = A(:, j);
  14.         for i = 1:j-1
  15.             R(i, j) = Q(:, i)' * A(:, j);
  16.             v = v - R(i, j) * Q(:, i);
  17.         end
  18.         R(j, j) = norm(v);
  19.         Q(:, j) = v / R(j, j);
  20.     end
  21. end
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement