求解线性方程组 - 预条件共轭梯度法 - MATLAB pcg - MathWorks 中国
https://ww2.mathworks.cn/help/matlab/ref/pcg.htmlPCG on a large sparse matrix from Finite difference method - MATLAB Answers - MATLAB Central
https://ww2.mathworks.cn/matlabcentral/answers/407845-pcg-on-a-large-sparse-matrix-from-finite-difference-method
方法一:全局变量法-不推荐
clc;clear n=10; global A A = sprand(n,n,0.5); % Sparse matrix with density 0.5 A = A\'*A; b=eye(10,1) [x3] = pcg(@afun,b,1e-8,100) function y=afun(x) global A y=A*x; end
方法二:匿名函数法-推荐
clc;clear n = 20; A = gallery(\'tridiag\',ones(n-1,1),n:-1:1,ones(n-1,1)); B= gallery(\'tridiag\',ones(n-1,1),n:-1:1,ones(n-1,1)); b = ones(20,1); myA = @(x) afun(x,A,B); x1 = pcg(myA,b) function y = afun(x,A,B) y=A\(B*x); end
请发表评论