我有两个变量形式的矩阵,A
它们b
是我的 matlab 函数的输入(发布在下面)。我想从结果矩阵中计算
用于矩阵逆运算(矩阵除法)的有效数字。但是,我不知道从哪里开始(matlab 或数学)来采用这种方法。帮助?A
b
更多上下文,使用平方线性系统(Ax=b)
,我正在查看它是奇异的还是非奇异的,并试图找到一个或多个解决方案。
% x = answer
% y = 0 if no solution, 1 if nonsingular, 2 if many solutions
% z = p is number of sig figs
%
function [ x, y, z ] = squareLinSysSolv(A, b)
if det(A) == 0
% Matrix is singular and therefor many solutions
x = A\b;
y = 0; % Used as place holder to compile
z = 5; % Used as place holder to compile
elseif det(A) ~= 0
% Matrix does not equal to zero (perhaps a number very close to it or
% far from it) and therefor has a unique solution.
x = A\b;
y = 1; % Used as place holder to compile
z = 5; % Used as place holder to compile
end
end
编辑:
为了更清楚一点,z 应该是一个整数,它近似于(上限或下限)A\b
计算的有效数字的十进制数。
测试用例:
预期的测试/规格表。两者都是矩阵A
,b
结果应该是这样的。
A =
1.5000 2.3000 7.9000
6.1000 3.2000 13.0000
13.0000 21.0000 76.0000
b =
1
3
5
>> [x,y,z] = squareLinSysSolv(A,b)
% the result of x = A\b
x =
0.8580
3.0118
-0.9132
% determinant is not equal to zero
y =
1
% Amount of sig figs/precision in calculation
z =
15