I have to write a code in matlab for the algoritm below (preconditioned conjugate gradient).(adsbygoogle = window.adsbygoogle || []).push({});

http://img265.imageshack.us/img265/3371/82526305tx0.png [Broken]

But in the code I've written there is a mistake (aside from the fact that I left out A and b) since it isn't converging.

Code (Text):

u = [ 0 ;zeros(n-2,1); 0];

k = 0;

r = b;

%algorithm

while r>1e-8

z=inv(M)*r;

k = k+1

if k==1

p = z;

r_1 = b;

z_1 = z;

else

beta = (r_1'*z_1)/(r_2'*z_2);

p = z_1+ beta*p;

end

alpha = (r_1'*z_1)/(p'*A*p);

u = u + alpha*p;

r= r_1-alpha*A*p;

r_2 = r_1;

r_1 = r;

z_2 = z_1;

z_1 = z;

end

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab Cg algorithm

**Physics Forums | Science Articles, Homework Help, Discussion**