MATLAB代码逐行解释:高斯消元法求解线性方程组及误差分析
clc; % 清空命令窗口 clear; % 清空工作区 A = [10 7 8 7; 7 5 6 5; 8 6 10 9; 7 5 9 10]; % 定义一个4x4的矩阵A b = [32; 23; 33; 31]; % 定义一个4x1的列向量b An = [10 7 8.1 7.2; 7.08 5.04 6 5; 8 5.98 9.89 9; 6.99 5 9 9.98]; % 定义一个4x4的矩阵An x = Gauss(A, b); % 调用高斯消元法计算方程组Ax=b的解x xn = Gauss(An, b); % 调用高斯消元法计算方程组Anx=b的解xn disp('The det and eigvalues of A are:'); % 输出A的行列式及特征值 det(A), eig(A) disp('The 2-norm of A is:'); % 输出A的2-范数 cond(A, 2) disp('The value of dx is:'); % 输出dx=xn-x dx = xn - x disp('The 2-norm of dx is:'); % 输出dx的2-范数 norm(dx, 2) disp('The relative error of x is:'); % 输出x的相对误差 norm(dx, 2) / norm(x, 2) disp('The relative turbulance of A is:'); % 输出A的相对扰动 norm(An - A, 2) / norm(A, 2)
原文地址: https://www.cveoy.top/t/topic/n1Nx 著作权归作者所有。请勿转载和采集!