📄 jacobi.m
字号:
function [X,n]=jacobi(A,b,X0,e,N0)
% input A is an N*N nonsingular matrix
% b is an N*1 matrix
% e is the tolerance for iterations
% output X is an N*1 matrix; the jacobi iterations approximation to
% the solution of AX=b
% N0 is the maximum number of iterations
%rou=norm(eig(A));
%if rou>=1
% disp(sprintf('the process of iteration is diverge'));
% return;
%end
N=length(b);
X=X0;
Y=ones(N,1);
for k=1:N0
for i=1:N
Y(i)=b(i);
for j=1:N
if j~=i
Y(i)=Y(i)-A(i,j)*X(j);
end
end
Y(i)=Y(i)/A(i,i);
end
error=norm(X-Y);
if error<e
n=k;
X=Y;
break;
end
n=-1;
X=Y;
end
if n==-1
disp(sprintf('false'));
n=N0;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -