function [Q,R] = obn(V)

[m,n] = size(V)

A = V
Q = zeros(n,n)

for j = 1:n
    
    % take column j of V
    %v = V(:,j)

    for i = 1:j-1
        %a = V(:,i)
        %b = v'
        %c = a * b
        
        %v = v - dot(v, V(:,i))*v
        % v = v - dot(V(:,i), v)*V(:,i)
        % v = v - V(:,i)*v' % proj (V(:,i), V(:,j))

        % \mathbf{v}_j \leftarrow \mathbf{v}_j - \mathrm{proj}_{\mathbf{v}_{i}}
        % \, (\mathbf{v}_j) (remove component in direction vi)
        
        m = (V(:, j)'*V(:, i)) / (V(:, i)'*V(:, i));
        V(:, j) = V(:, j) - m * V(:, i);

    end
    
    Q(:, j) = V(:, j) / norm(V(:, j));
    %v = norma(v)
    %V(:,j) = v
end

R = Q' * A
end

%obn([1,1,1;
%     0,1,1;
%     0,0,1])
