Ada*_*dam 6 matlab matrix linear-algebra matrix-multiplication
我在变量的形式两个矩阵A并b为输入到我的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
Run Code Online (Sandbox Code Playgroud)
编辑:
为了使它有点清楚,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
Run Code Online (Sandbox Code Playgroud)
我和丹在一起。我不明白这个问题,也不明白你如何/在哪里计算 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
Run Code Online (Sandbox Code Playgroud)
我想我也太笨了。:)
布雷特