title: How to find if a matrix is Singular in Matlab
body: <p>I use the function below to generate the betas for a given set of guess lambdas from my optimiser.   </p>
  
  <p>When running I often get the following warning message:</p>
  
  <p>Warning: Matrix is singular to working precision. 
  In NSS_betas at 9
  In DElambda at 19
  In Individual_Lambdas at 36</p>
  
  <p>I'd like to be able to exclude any betas that form a singular matrix form the solution set, however I don't know how to test for it?</p>
  
  <p>I've been trying to use rcond() but I don't know where to make the cut off between singular and non singular?</p>
  
  <p>Surely if Matlab is generating the warning message it already knows if the matrix is singular or not so if I could just find where that variable was stored I could use that?</p>
  
  <pre><code>function betas=NSS_betas(lambda,data)
  
  mats=data.mats2'; 
  lambda=lambda;
  yM=data.y2';
  nObs=size(yM,1);
  G= [ones(nObs,1) (1-exp(-mats./lambda(1)))./(mats./lambda(1)) ((1-exp(-mats./lambda(1)))./(mats./lambda(1))-exp(-mats./lambda(1))) ((1-exp(-mats./lambda(2)))./(mats./lambda(2))-exp(-mats./lambda(2)))];
  
  betas=G\yM;
  r=rcond(G);
  
  end
  </code></pre>
  
  <p>Thanks for the advice:</p>
  
  <p>I tested all three examples below after setting the lambda values to be equal so guiving a singular matrix</p>
  
  <pre><code> if (~isinf(G))
    r=rank(G);
    r2=rcond(G);
    r3=min(svd(G)); 
   end
  </code></pre>
  
  <p>r=3, r2 =2.602085213965190e-16; r3= 1.075949299504113e-15;</p>
  
  <p>So in this test rank() and rcond () worked assuming I take the benchmark values as given below.</p>
  
  <p>However what happens when I have two values that are close but not exactly equal?</p>
  
  <p>How can I decide what is too close?</p>