% generate data

tol = 1e-8;
maxiter = inf;
freq = inf;
repeat = 50;

randn('seed',100);
rand('seed',100);

fprintf('version 6\n')
fid = fopen('DRAlt.txt','w');

for m = 100:100:500
  for n = 4000:1000:6000
  
    k = ceil(m/5);
  
    fDRmax = 0; fDRmin = inf;
    fAltmax = 0; fAltmin = inf;
    timeDR = 0; timeAlt = 0;
    iterDR = 0; iterAlt = 0;
    successDR = 0; successAlt = 0;
    failDR = 0; failAlt = 0;
  
    for ii = 1:repeat
    
      A = randn(m,n);
      x0 = randn(k,1);
      x1 = zeros(n,1);
      I = randperm(n); x1(I(1:k)) = x0;
      b = A*x1;
    
      fprintf(' Start DR\n')
      tDR = tic;
      [fval,z,x,y,iter] = DR_proj(A,b,k,tol,maxiter,freq);
      timeDR = timeDR + toc(tDR);
      iterDR = iterDR + iter;
      fDRmax = max(fDRmax,fval);
      fDRmin = min(fDRmin,fval);
      if fval < 1e-12
        successDR = successDR + 1;
      end
      if fval > 1e-6
        failDR = failDR + 1;
      end
    
      fprintf(' Start Alt\n')
      tAlt = tic;
      [fval2,x2,iter2] = Alt_proj(A,b,k,tol,maxiter,freq);
      timeAlt = timeAlt + toc(tAlt);
      iterAlt = iterAlt + iter2;
      fAltmax = max(fAltmax,fval2);
      fAltmin = min(fAltmin,fval2);
      if fval2 < 1e-12
        successAlt = successAlt + 1;
      end
      if fval2 > 1e-6
        failAlt = failAlt + 1;
      end
    
    end
  
    fprintf(fid,' %5d & %5d & %8.2f & %6.0f & %1.0e & %1.0e & %2.0f & %2.0f & %8.2f & %6.0f & %1.0e & %1.0e & %2.0f & %2.0f\n',...
      m, n, timeDR/repeat, iterDR/repeat, fDRmax, fDRmin, successDR, failDR, timeAlt/repeat, iterAlt/repeat, fAltmax, fAltmin, successAlt, failAlt);
  end

end

fclose(fid);