Message Boards Message Boards

How to Reduce Number of Iteration of Gradient Iterative Method

Posted 10 years ago

Hi All,

I want to solve a 5x5 matrix using gradient iterative method. After ~34000 iteration I got result in given stopping tolerance. But can we modify/improve my iteration so that we can find solution in less iteration say 30000 steps?

I have attached my code.

Thanks in advance,


POSTED BY: selahittin cinar
5 Replies

It does what you requested, that is, sues fewer iterations (factor of 10). Also each iteration does less work (fewer matrix-times-vector products).

Here is the full code I used.

n = 5;
amat = HilbertMatrix[n]; b = amat.ConstantArray[1, n]; 
x0 = ConstantArray[0, n];
pmat = LowerTriangularize[amat];
np = N[pmat]; nb = Flatten[N[b]]; nx0 = N[x0];
normb = Norm[nb];
iP = Inverse[np];

 gradient2 = 
   NestWhileList[(# + ((b - amat.#).(b - amat.#)/(b - 
             amat.#).amat.(b - amat.#))* iP.(b - amat.#)) &, 
    nx0, (Norm[b - amat.#]/normb > 10^-10) &];]

(* Out[779]= {0.456000, Null}

Out[780]= 3574

Out[781]= {0.99999955485, 1.00000817563, 0.999965167212, 1.00005215021, 0.999974653858} *)
POSTED BY: Daniel Lichtblau

Hi Daniel,

I used what you said and attached it.

But it is soooo fast!!! why is that?

Thank you so much..


POSTED BY: selahittin cinar

You did not try what I said. You used for the nesting function (# + iP.(b - A.#).(b - A.#)/iP.(b - A.#).A.iP.(b - A.#) iP.(b - A.#)) &. That is not the function I recommended to use. In particular I count four uses of that inverse iP in yours, and only one in mine.

POSTED BY: Daniel Lichtblau

Hi Daniel,

I tried what you said but nothing is change..

I am attaching my new code. Do you think it is wrong what I did in my code?

Thanks you so much..


POSTED BY: selahittin cinar

Flatten b so it is a vector, get rid of all the transposing because it's not needed for vector multiplication, define iP=Inverse[P], and try this for the nesting iterations:

 (# + ((b - A. # ).(b - A.# )/(b - A.# ).A.(b - A.# )) iP.(b - A.# )) &
POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract