0
$\begingroup$

I have made following matlab code for computing the Moore-Penrose inverse of a given matrix A.

A = randn(100)            % given matrix  beta = 1/norm(A,2)^2  x0 = beta.*A'             % initial approximation, A' is the transpose of matrix A  k = 0;  iter = 0  f = 1 ;  I = eye(100);   while (f > 1.0e-007)  x1 = 2*x0 - x0*A*x0;   % x1 is approximation of Moore-Penrose inverse of matrix A  iter = iter+1  a = norm(A*x1*A-A, 2);  %  error norm   b = norm(x1*A*x1 - x1);`   % error norm  c = norm ((A*x1)' - A*x1, 2 );   % error norm  d = norm ((x1*A)' - x1 *A, 2);   % error norm  B = [a, b, c, d];  f = max(B);  x0 = x1;  end 

Since matrix A is changing after every iterations hence values of a,b ,c and d are also changing. I am trying to compute average of values a, b, c and d after hundred repetitions but I am unable to do so. Could anybody help me? I would be very much thankful to you.

  • 0
    @macydanim Exactly the same thing I wanted to ask.:)2013-04-11

1 Answers 1

1

I think the reason, why the mentioned approaches didn't work was because everyone was assuming ( me too at first ) that you want to have the mean value for a during the iterations with one single matrix. However, you seem to want the mean value of a at the end of the algorithm, averaged for several runs with different matrices.

If I understand this correct, the below code should work. (Note $M=10$ instead of $M=100$, line 2)

clc              % cleans the output screen, I don't like old information... M = 10;          % number of matrices for which perform the calculation E = zeros(M,4);  % we will store for all M iterations all the 4 values  fprintf('\nPerforming %i iterations in total.\n',M);  % this is just output..  %now the important part, we will perform your calculation M times  %therefore, we loop over your calculation with a for loop for i = 1:M      fprintf('Iteration %i is running...\n' ,i ) % output..      A = rand(100);            % given matrix     beta = 1/norm(A,2)^2;     x0 = beta.*A';             % initial approximation, A' is the transpose of matrix A     k = 0;     iter = 0;     f = 1 ;     I = eye(100);       while (f > 1.0e-7)          x1 = 2*x0 - x0*A*x0;   % x1 is approximation of Moore-Penrose inverse of matrix A         iter = iter+1;         a = norm(A*x1*A-A, 2);  %  error norm         b = norm(x1*A*x1 - x1);   % error norm         c = norm ((A*x1)' - A*x1, 2 );   % error norm         d = norm ((x1*A)' - x1 *A, 2);   % error norm          B = [a, b, c, d];           f = max(B);          x0 = x1;      end      % at this point, your calculation has been performed for a matrix A.     % We will now store  the values for a,b,c,d of the last iteration in the matrix E     E(i,:) = B;  end  % here we print the mean value of a, which is mean(E(:,1)) fprintf('\nMean value of a =%s\n', mean(E(:,1))); 
  • 1
    Dear sir everything is $c$lear now. No queries. Heartily thanks. :)2013-04-11