% Test Script P1

clc
randn('seed',0)
m = 100; n = 20; r = 5;
F = randn(m,r); G = randn(n,r); b = randn(m,1);

xB = LowRankLS(F,G,b);

% Naive method...
A = F*G';
[Q1,R1,pVec] = qr(A,0);
b = Q1'*b;
xB0 = zeros(n,1);
xB0(pVec) = [R1(1:r,1:r)\b(1:r);zeros(n-r,1)];

% Compare...

format long
TwoSolutions = [xB xB0]
format short