📄 my_fgmres.m
字号:
function [x,iter,flg,inner]=my_fgmres(A,b,tol,restart,maxit,M1,M2,p_type,x0)
% FGMRES
% [x,iter,flg,inner]=my_fgmres(A,b,tol,restart,maxit,M1,M2,p_type,x0)
% this is the implementation of preconditioned GMRES method
% m is the number of restart,
% p is the preconditioning type, p=0: implicit preconditioner; p=1 explicit
% preconditioner
% flg=0 success; flg=1 fail;
% Developed by: Plum_Liliang UESTC China
% Date : 2006-06-30
% checking input arguments and assign default value
[m,n]=size(A);
if m~=n
error('The coefficient matrix must be square!')
end
[m_b,n_b]=size(b);
if n_b~=1
error('b must be a vector!')
end
if m~=m_b
error('The right-hand vecotor must have the same length of A!')
end
if nargin<2
error('Not enough input arguments!');
end
if nargin<3 | tol==[]
tol=1e-6;
end
if nargin<4 | restart==[]
restart=min(10); % the maximum outer iteration is assigned to 10 defaultly
end
if nargin<5 | maxit==[]
maxit=min(20,n);
end
% if 'b' is zero then the solution is zero
norm_b=norm(b);
if norm_b==0
x=0;
iter=0;
x=0;
return;
end
% Check the preconditioners
if nargin>=6 & ~isempty(M1)
existM1=1;
if ~isequal(size(M1),[m,n])
error('The preconditioners M1 should match the size of A!')
end
else
existM1=0;
end
if nargin>=7 & ~isempty(M2)
existM2=1;
if ~isequal(size(M2),[m,n])
error('The preconditioners M2 should match the size of A!')
end
else
existM2=0;
end
if nargin<8 | p_type==[]
p_type=0;
end
% check the initial guess
if nargin<9 | x0==[]
x0=zeros(n,1); % the initial guess is defaultly 0-vector;
else
[m_x,n_x]=size(x0);
if m_x~=n | n_x~=1
error ('The initial guess should be has the same size with the right-hand vector!');
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -