Matlab 共轭梯度法求解任意线性方程组!求详细解释如下程序
functionx=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;fork=1:numel...
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 展开
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 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询