Matlab矩阵乘法计算有效数字

标签 matlab matrix linear-algebra matrix-multiplication

我有两个矩阵,形式为变量 Ab 作为输入 到我的 matlab 函数(在下面发布)。 我想计算 有效数字用于矩阵逆运算(矩阵除法) 从结果 A, b 矩阵。但是,我不知道从哪里开始 (matlab 或数学)来实现这种方法。帮忙?

更多上下文,使用方形线性系统 (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 时的有效数字的十进制数。

测试用例: 预期的测试/规范表。 Ab 都是矩阵,结果应该是这样的。

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

最佳答案

我和 Dan 在一起。我不明白这个问题,也不知道你是如何/在哪里计算 z 的。首先,你答案显示的位数与计算答案时的有效位数无关。其次,您有两种情况:det(A)==0 和 det(A)~=0。在这两种情况下,您似乎都在设置 z = 5。(您必须在其他地方做一些您没有显示的事情来计算 z = 15?您是如何计算 z 的?)

此外,请认识到有效数字的数量将取决于您的数据类别。双>单>整数...

而且...只是为了提高效率,我不知道 A 的大小(也不知道计算它的行​​列式需要多少开销),但是没有理由计算它两次:

if det(A)==0
    % case 1
else % NOT: elseif det(A)~=0
    % case 2
end

我想我也很笨。 :)

布雷特

关于Matlab矩阵乘法计算有效数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13073846/

相关文章:

matlab - 通过 Matlab 中的 'ID' 字段加入具有相同字段名的 2 个结构

C - 以某种密度填充矩阵

r - 有没有办法将更大列表中的数据帧列表汇总在一起?

math - 二维空间游戏中的线性代数

c++ - 求解联立方程的算法

c++ - 平面和球体光线追踪的交集

普通 RV 上的 Matlab 'entropy()'

matlab - 在另一个数据系列下方绘制一个数据系列

matlab - 在 MATLAB 中有效地循环向量

matlab - 在 MATLAB 中旋转 3D 矩阵