Need little help in making matlab code related with iteration methods

386 Views Asked by At

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.