⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jacobi_iterative_method.m

📁 数值分析中的JOCOBI迭代的MATLAB源程序
💻 M
字号:
function Jacobi_iterative_method

format long;
A=input('please input coefficient matrix row by row: ');
b=input('please input the right value of the function by column: ');
X0=input('please input the initial value of vector X by column: ');
e=input('please input permitted error limited value: ');
N=input('please input the MAX iterative times: ');

K=0;
n=length(A(1,:));
D=diag(diag(A));
B=eye(n)-D^-1*A;
g=D^-1*b;
X1=B*X0+g;
K=K+1;
fprintf('\n');
fprintf('The initial value of X as follows: ');
fprintf(1,'%f  ', X0');
fprintf('\n');
fprintf(1,'The %d times iterative X value is:',K);
fprintf(1,'%15.12f',X1);
fprintf('\n');

while sqrt(sum((X1-X0).^2))>e&K<N
    K=K+1;
    X0=X1;
    X1=B*X0+g;
    fprintf(1,'The %d times iterative X value is: ',K);
    fprintf(1,'%15.12f',X1);
    fprintf('\n');
end

if K<N
    fprintf('\n');
    disp(['The result value of X is: ' num2str(X1')]);
    disp(['The iterative times is: ' num2str(K)]);
    fprintf('\n');
else
    fprintf('\n');
    disp('Warning: It is not a convergence function!');
    fprintf('\n');
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -