%
%  This function allows us to play with svd
%  The signal to noise ratio (SNR) is in dB
%
function  laptop11(SNR,mu,Nt);
%
  Z = [-0.2042 0.0559 0.3715 -0.2077;
       0.1347 0.2208 0.5294 0.1336;
       0.4803 0.3889 0.6862 0.4670;
       0.6078 0.6088 1.2159 0.6081];
   X = [1;1;1;1];
   
%  Z = [-0.0505 0.0683 0.1175 0.0538 0.1709;
%        0.2215 0.1729 0.0005 0.2794 0.2963;
%        0.4663 0.4675 -0.0623 0.4237 0.3403;
%        -0.1871 0.0701 0.2650 0.0460 0.3136;
%        0.2109 0.0203 0.0513 -0.0603 0.0717];
%
% X = [1;1;1;1;1];
%
 [m,n] = size(Z);
%
% open an output file
%
  fid = fopen('laptop11.dat','wt');
  fid = 1;
%
  fprintf(fid,' File laptop11, SNR = %f dB, mu = %f, Nt = %d \n\n', SNR,mu,Nt); 
%
%  compute a forward solution
%
  Y = Z * X;
  fprintf(fid,'The true forward solution (Y) is: \n');
  fprintf(fid,' %f \n',Y);
%
%  now compute the zero noise inverse
%
  x = inv(Z)*Y;  
  fprintf(fid,'\nThe estimated value of x with no noise is: \n');
  fprintf(fid,' %f \n',x);
%
%  now compute the singular value
%  decomposition and try again
%
  [U,S,V]=svd(Z);
  beta = U'*Y;
  beta_no_noise = beta;
  alpha = inv(S)*beta;
  x = V*alpha;
  fprintf(fid,'\nThe (no noise) svd estimate of x is \n');
  fprintf(fid,' %f \n',x);
%
%  set the random number generator to a new seed each time
%
   randn('state',sum(100*clock'))
%
%  now add noise to the observation
%
  RMS = norm(Y)/sqrt(length(Y));
  sigma = RMS/(10^(0.05*SNR));
  noise = sigma*randn(length(Y),1);
%
%  determine the new y with the noise added to the observation
%
  Y_noise = Y + noise;
  fprintf(fid,'\nThe new observed data (Y) with added noise is: \n');
  fprintf(fid,' %f \n',Y_noise);
%
%  determine the inverse based on the new y
%
  x = inv(Z)*Y_noise;
  fprintf(fid,'\nThe estimated x based on the inverse of Z is: \n');
  fprintf(fid,' %f \n',x);
%
%  determine the corresponding forward computed value
%
  Y = Z*x;
  fprintf(fid,'\nThe corresponding Y is: \n');
  fprintf(fid,' %f \n', Y');
%
%  now let's look at the singular values
%
  sigma = diag(S);
  fprintf(fid,'\nThe singular values are: \n');
  fprintf(fid,' %f \n',sigma');
%
%  determine beta
%
  beta = U'*Y_noise;
%
%  Tikhonov regularization
%

%
%  TSVD
%
 