我有两个矩阵,形式为变量A和b,并作为我的Matlab函数(在下面发布)的输入。 我想从结果A,b矩阵中计算用于矩阵求逆操作(矩阵除法)的有效数字。 但是,我不知道从哪里开始(Matlab或数学上)来处理这种方法。需要帮助吗?
更多背景信息,使用一个方形线性系统(Ax = 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
A\b
在某些有效数字处计算的十进制数的上限或下限值。 - Adam