-1

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

then I try to see if F_est - F is zero and it is not. Any ideas. Much aprreciated.

**** EDIT after comments

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

Am I able to recover F if I have Y and S?

Tyrone
  • 167
  • 1
  • 10

1 Answers1

2

When you create Y, you are replacing its values continuously. For any value of pair of i,k you are overwriting Y jtimes!

Those 2 codes are not equivalent, as F_est(i,j,k) computed only once, but you have Y(i,k) j times.

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

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • 1
    What you are saying is that `Y` contains only information from the 2D plane `F(:,size(F,2),:)`, so the rest of `F` cannot be recovered. – Cris Luengo Jul 26 '18 at 22:41
  • @CrisLuengo indeed. Its just bad math though, you can not multiply those things together. – Ander Biguri Jul 26 '18 at 22:42
  • 1
    Well, *technically* you can. It just doesn't mean anything. :) – Cris Luengo Jul 26 '18 at 22:43
  • @AnderBiguri thank you! I edited the question. Can you please help me with last part? – Tyrone Jul 26 '18 at 22:46
  • @Tyrone It only makes sense if you try to explain what you are doing. However, please note that what you propose is mathematically wrong, has nothing to do with code. You can not multiply a 3D matrix by a 2D matrix. – Ander Biguri Jul 26 '18 at 23:03
  • So I assume I cant also multiply a 2D matrix with 1 D matrix, as I did in that small piece of code I added later after edits.? Thanks – Tyrone Jul 26 '18 at 23:07
  • @AnderBiguri regarding my updated part, just wondering if I can recover F given Y and S? – Tyrone Jul 26 '18 at 23:10
  • 1
    @Tyrone You need to get out of code, and back to paper. You can not create Y, so no, you can not recover F. Stop trying random code. If you want help, I suggest you open a new question explaining the real problem you are triying to solve, not your attempted code. – Ander Biguri Jul 26 '18 at 23:12