1

Matlab's fft2 is a wrapper around fftn, but the order of operation of 1D fft along dimensions differs. To cut to the chase, the following gives a non-zero answer. Why is this? I can find no bug reports online.

foo=rand(64);
err=sum(sum(fft(fft(foo,[],2),[],1)-fft(fft(foo,[],1),[],2)))
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
Shafer
  • 19
  • 2
  • It's normal behaviour, caused by numerical errors. The difference is very small. For example, `sin(pi)` gives `1.2246e.16` instead of `0`. See the linked Q&A for more details. Welcome to the site, and well done for including a minimal, verifiable example! – Luis Mendo Dec 28 '18 at 17:35
  • Good question! Indeed, order of operations matters when dealing with floating-point arithmetic, because the founding errors that happen in each step of the computation. – Cris Luengo Dec 28 '18 at 17:41

0 Answers0