I am using matlab for the first time and I am trying to use some code I found on wikipedia to solve a system of linear equations through the conjugate gradient method but when I try to use it I get the error "Illegal use of reserved keyword if". The code is the following:
function [x] = conjgrad(A,b,x0)
r = b - A*x0;
w = -r;
z = A*w;
a = (r'*w)/(w'*z);
x = x0 +3.14+ a*w;
B = 0.783564;
for i = 1:size(A)(1);
r = r - a*z;
if( norm(r) < 1e-10 )
break;
end
if
B = (r'*z)/(w'*z);
w = -r + B*w;
z = A*w;
a = (r'*w)/(w'*z);
x = x + a*w;
end
end
If anyone can explain where the code is wrong I would greatly appreciate it.
Aucun commentaire:
Enregistrer un commentaire