function [Q,R] = solution_hw5_p3a(A)
%solution_hw5_p3a Computes the QR decomposition using Classical Gram-Schmidt
%   A - The matrix to compute the QR of 
%   Q - Orthonormal matrix
%   R - Upper triangular matrix
%       Note: This uses the algorithm outlined in class and Trefethen. 
%         This also only works if m>n.

    [m, n] = size(A);
    
    R = zeros(n, n);
    Q = zeros(m, n);
    
    for j=1:n
        v = A(:, j);
        for i=1:j-1
            R(i,j) = dot(Q(:,i), A(:,j));
            v = v - R(i,j)*Q(:,i);
        end
        R(j, j) = norm(v, 2);
        Q(:, j) = v./R(j, j);
    end
            

end

