% Total LS.

delta = 1e-2;
fprintf('delta = %e\n', delta)

fprintf('Index\tfl\tit\n')

idx_list = [4, 6, 8, 12, 16, 24, 32, 48, 64]';

for k = 1 : length(idx_list)
   
   idx = idx_list(k);
   
   mC = ceil(1.5 * idx);
   nC = idx;
   mD = mC;
   nD = nC;

   maxit = max(4 * idx * idx, 50);
   steptol = (nC + nD) * eps;

   m = mC * mD;
   n = nC * nD;

   C = 5 - 10 * rand(mC,nC);
   D = 5 - 10 * rand(mD,nD);
   E = delta * (5 - 10 * rand(m, n));
   e = delta * (1 - 2 * rand(m, 1));
   x = 1 - 2 * rand(n, 1);

   % b = ( kron(C,D) + E) * x - e;
   b = KPmult(C, D, x) + E * x - e;
   
   clear E e

   % Inverse Iteration.
   flops(0);
   [x1, it1] = TotalLS(C, D, b, maxit, steptol);
   fl1 = flops;

   % Results.
   %diff = norm(x1 - x2) / norm(b);
   %fprintf('%d\t%d\t%d\t%d\t%d\t%e\n', idx, fl1, it1, fl2, it2, diff)
   fprintf('%d\t%d\t%d\n', idx, fl1, it1)

end % for k
