# Need matlab help related with the iteration method

I am reading an iteration method for computing the Moore- Penrose genralized inverse of a given matrix $A$, which is given as follows:

$X_{k+1} = (1+\beta)X_{k} - \beta X_{k} A X_{k}$

where $X_{k}$, k = 0,1,... is a sequence of approximations for computing Moore- Penrose genralized inverse

$X_{0} = \beta A'$ is the initial approximation , $0<\beta\leq 1$ and $A'$ is the transpose of matrix $A$

$d_{k} = \|X_{k+1} - X_{k}\|_{fro}$ is the error matrix norm (frobenius norm)

I have made following matlab program for computing Moore- Penrose genralized inverse by above mentioned method. But i am unable to make code for stopping criterion which says that.

perform the iteration untill

$|d_{k+1}/d_{k} - \beta -1|> 10^{-4}$

-
You can post the MATLAB code on your post. Check the "code sample" button, the one with the "{}". –  Rod Carvalho Sep 11 '12 at 14:02
Why are you unable to make code for the stopping criterion? Do you mean do you don't know how to do it, or that when you try, it doesn't work? Can't you use a while loop? –  Christopher A. Wong Sep 12 '12 at 3:54
@ChristopherA.Wong Dear sir, i m beginner in matlab. I don't know how to do that? I need help. –  srijan Sep 12 '12 at 4:51
@srijan, you should change your for loop to a while loop that checks the value of the error. –  in_wolframAlpha_we_trust Sep 14 '12 at 8:34

The prep before your loop should stay the same. The appropriate script is

A = ...; % as you have given
beta = ...; % whatever you want
X0 = beta*A'; % calculate initial estimate

% (these initial values may need to be changed, I don't have a copy of
%    matlab in front of me)
dklast = NaN; dk = NaN; % initialise to begin loop

iter = 0;
maxiter = 100;

while (abs(dk/dklast - beta - 1) > 1e-4) && (iter < maxiter) % loop until tolerance met
iter = iter + 1; % keep count of iteration

X1 = (1+beta)*X0 -beta*X0*A*X0; % calculate new iterate

dklast = dk; % move old difference "new estimate to previous iterate"
dk = norm(X1-X0,'fro'); % determine new difference

X0 = X1; % copy current iterate to "old" iterate for next iteration

end


I am wondering why you are using this convergence test at all. I would recommend using

dk = norm(X1*X0-I,'fro');


which measures how close X1 is to the left inverse of $A$. Your termination criteria would then be

while dk > (some_tolerance) && iter < maxiter
....
end


As you currently have, you are measuring how much X1 changes from X0, which may be small, but still not an approximate inverse (or pseudoinverse) for $A$.

-
First of all thanks for replying me. I took beta = 1/norm (A,2)^2 , but program is not running. –  srijan Sep 14 '12 at 8:58
What error are you receiving? I have seen this algorithm with beta=1, not anything else. As I said, those two lines may need to be changes. You could initialise the process with dklast=-30 and dk=-20 and it should work then. –  Daryl Sep 14 '12 at 10:05
Programm is not running..just Matrix A is coming...not getting x1.. –  srijan Sep 14 '12 at 10:07
If X1 is not defined at the end of the iteration, then the loop is not running. As I said in my above comment, try with the values I have given there. The NaN terms may be invalidating the condition. –  Daryl Sep 14 '12 at 10:10
Dear i am not getting what you mean by x1 is not defined at the end of iteration bro..x1 is the sequence of approximation..nd you have defined that –  srijan Sep 14 '12 at 10:13