赞
踩
- % Matlab 代码
- close all; clear all; clc;
- A = [9, -1, -1;
- -1, 10, -1;
- -1, -1, 15];%方程系数矩阵
-
- b = [7; 8; 13]; %方程右端常数项
- D = diag(diag(A)) %对角线
- L = -( tril(A) - diag(diag(A)) ); %下三角矩阵
- U = -( triu(A) - diag(diag(A)) ); %上三角矩阵
- X = [0;0;0];
- X_New = [0;0;0];
- i=0;
- while i<10
- X_New = inv(D)*(L+U)*X + inv(D)*b;
- X = X_New;
- i = i + 1;
- end
- X %输出线性方程组的解
- % Matlab 代码
- close all; clear all; clc;
- A = [9, -1, -1;
- -1, 10, -1;
- -1, -1, 15];%方程系数矩阵
-
- b = [7; 8; 13]; %方程右端常数项
- D = diag(diag(A)); %对角线
- L = -( tril(A) - diag(diag(A)) ); %下三角矩阵
- U = -( triu(A) - diag(diag(A)) ); %上三角矩阵
- X = [0;0;0];
- X_New = [0;0;0];
- i=0;
- while i<10
- X_New = inv(D-L)*U*X + inv(D-L)*b;
- X = X_New;
- i = i + 1;
- end
- X
-
-
- %加入循环中值准则
- close all; clear all; clc;
- A = [9, -1, -1;
- -1, 10, -1;
- -1, -1, 15];%方程系数矩阵
-
- b = [7; 8; 13]; %方程右端常数项
- D = diag(diag(A)); %对角线
- L = -( tril(A) - diag(diag(A)) ); %下三角矩阵
- U = -( triu(A) - diag(diag(A)) ); %上三角矩阵
- B = inv(D-L)*U;
- f = inv(D-L)*b;
- X = [0;0;0];
- X_New = [0;0;0];
- C = norm(B,2) / (1 - norm(B,2));
- Out = 1;
- while Out > 0.0000001
- X_New = B*X + f;
- Out = C*norm(X_New-X,2)
- X = X_New;
- end
- X %输出线性方程组的解
-
- %计算B的谱半径看是否小于1收敛
- [V,Dig] = eig(B);
- max(max(abs(Dig)))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。