Code covered by the BSD License  

Highlights from
Making square matrix singular.

Making square matrix singular.

by

 

Making any given non-singular square matrix singular by perturbing with prescribed distribution.

M_singular
function M_singular
%     Making a non-sigular square matrix singular
%      by perturbing with prescribed distribution
%     F C Chang    04/21/2013

      Ao = [1.5 -0.5 -1.5 2.0 -3.0; -3.0 1.5 2.0 -3.0 4.0; -1.0 0.5 1.0 -1.0 1.0; ...  
            2.0 -0.5 -1.0 2.0 -2.0; -1.0 0.5 0.0 -0.5 0.5];    % write-in ' A = Ao '
      disp(" A is any non-singular square matrix, e.g. magic(5), rand(3), or write-in, etc."),
      A = input('Enter A = '); 
      DetA = det(A);
   if abs(DetA) < 1.e-8, disp("***  The original matrix [A] is singular ! ***"), return; end;
      AI=inv(A);
      n = size(A,1),     A,AI,DetA,
      disp("e.g.  if n = 5,  then  r = [1 0 -0.3 -4 -0.9],  c = [-2i 0.3 101 0 1-2i], "),
      r = input('Enter r = '); 
      c = input('Enter c = ');
      d = r'*c;              % prescribed distribution on grids
      S = sum(sum(d.*AI'));
      D = d/S;
      AD = A-D; 
      DetAD = det(AD);   d,S,D, AD,DetAD,
   if abs(DetAD) < 1.e-8, disp("***  The perturbed matrix AD=[A-D] is singular !  ***"), end;

Contact us