这两个矩阵为何不相等? [英] How come these two matrices are not equivalent?
问题描述
假设我们有一个3维数组F
和2维矩阵S
.
首先,我找到一个矩阵Y
,该矩阵将F
乘以S
.然后,我尝试从Y
中找到F
的估计值(简称为F_est
),作为我代码中的健全性检查.
谁能看到逻辑上的缺陷,但我似乎不知道为什么F_est
并不完全是F
.
Assume we have a 3 dimensional array F
and 2 dimensional matrix S
.
First I find a matrix Y
which is F
multiplied by S
. Then I try to find an estimate of F
(lets call it F_est
) from Y
as sanity check in my code.
Can anyone see a flaw in logic, I dont seem to know why F_est
is not exactly F
.
F= randn(2,4,600);
S= randn(4,600);
for i =1:size(F,1);
for j=1:size(F,2)
for k= 1:size(F,3)
Y(i,k)= F(i,j,k) * S(j,k);
end
end
end
for i =1:size(F,1)
for j=1:size(F,2)
for k= 1:size(F,3)
F_est(i,j,k)= Y(i,k) / S(j,k);
end
end
end
然后我尝试查看F_est - F
是否为零,否则为零.有任何想法吗.非常感谢.
then I try to see if F_est - F
is zero and it is not. Any ideas. Much aprreciated.
****评论后编辑
基于我得到的答案,我想知道下面的代码是否有意义?
Based on the answers I got I am wondering if the code below makes any sense?
for k=1:size(F,3)
Y(:,k) = squeeze(F(:,:,k)* S(:,k)
end
如果我有Y和S,我可以恢复F吗?
Am I able to recover F if I have Y and S?
推荐答案
创建Y
时,将连续替换其值.对于i,k
对的任何值,您将覆盖Y
j
倍!
When you create Y
, you are replacing its values continuously. For any value of pair of i,k
you are overwriting Y
j
times!
这两个代码并不等效,因为F_est(i,j,k)
仅计算一次,但是您有Y(i,k)
j
次.
Those 2 codes are not equivalent, as F_est(i,j,k)
computed only once, but you have Y(i,k)
j
times.
我不知道您要做什么,但是未定义3D矩阵与2D矩阵的乘法,并且它不是2D矩阵
I don't know what you are trying to do, but a multiplication of a 3D matrix by a 2D matrix is not defined, and its not a 2D matrix
这篇关于这两个矩阵为何不相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!