資源簡介
共軛梯度法matlab程序
function x = cg(A,b)
tol=1e-10;
r = b + A*b;
w = -r;
z = A*w;
s = w'*z;
t = (r'*w)/s;
x = -b + t*w;
for k = 1:numel(b);
r = r - t*z;
if( norm(r) < tol )
return;
end
B = (r'*z)/s;
w = -r + B*w;
z = A*w;
s = w'*z;
t = (r'*w)/s;
x = x + t*w;
end
代碼片段和文件信息
function?x?=?cg(Ab)
tol=1e-10;
r?=?b?+?A*b;
w?=?-r;
z?=?A*w;
s?=?w‘*z;
t?=?(r‘*w)/s;
x?=?-b?+?t*w;
for?k?=?1:numel(b);
????r?=?r?-?t*z;
????i
評論
共有 條評論