function [Q, R] = givensQR(A)
	% Bottom-up QR factorization using Givens rotations
	% No pivoting - requires m>=n

	[m n] = size(A);
	Q = eye(m, m);
	R = A;
	
	for j=1:n
		for i=m:-1:j+1
			[c, s] = givens(R(i-1, j), R(i, j));

			R([i-1 i], j:n) = [c s; -s c] * R([i-1 i], j:n);
			R(i, j) = 0;
			Q(:, [i-1 i]) = Q(:, [i-1 i]) * [c -s; s c];
		end
	end
end
