Upgraded Matlab from 2022b to 2023b and I've noticed a floating point error

18 views (last 30 days)
I have recently upgraded my Matlab version from 2022b to 2023b and I have noticed a floating point error when running my code in windows, but not when I run it in linux. I'm sure my code hasn't changed at all so its unclear what's happened. Any ideas why this change has happened?
  8 Comments
John D'Errico
John D'Errico on 13 Dec 2023
Note that a difference of 1e-12 MAY be just floating point trash. It completely depends on the size of the other numbers involved. That is, a difference of one bit in the least sigificant bit of different size numbers may easily be as large as 1e-12. eps will tell you that.
eps(1)
ans = 2.2204e-16
eps(10000)
ans = 1.8190e-12
eps(1000000)
ans = 1.1642e-10
So a one bit difference in the least significant bits of the number 10000 is roughly 1e-12. If that is what you are seeing, if the numbers involved in your computation were of that magnitude, then you are probably just seeing floating point trash. The difference may be due to a subtly different version of the BLAS usd by the two different systems, so some numbers may have been added in a different order, getting a subtly different result.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 13 Dec 2023
As others have said it's impossible to give a firm answer with the limited amount of information you provided. Some possibilities:
  • We fixed a bug in one of the functions you were using that results in a different answer on Windows. You could check the Release Notes and/or the Bug Reports to see if any major changes affected one or more of the functions you used. [However, note that not all changes and not all bugs are reported in those two sections of the website.]
  • We upgraded one of the numeric libraries (to enable new functionality, to improve accuracy, to improve performance, and/or to fix bugs) and the new library version gives an answer that is still correct but is not bit-for-bit identical to the answer in the previous release, perhaps due to a different amount of optimization performed in the library.
  • We introduced a new bug in one of the functions you're using.
  • The data on which you're operating could have changed.
Just because the answer is different doesn't necessarily mean it's wrong. So is the difference large enough that the answer is wrong or is it different but right? As an example, if the theoretical answer a function (let's say something like the integral function) should return using exact arithmetic was 0.5, the older version gave an answer of 0.49999999, and the newer version gives 0.50000001, is that necessarily wrong or a problem? Impossible to say without more information.
  2 Comments
Hannah
Hannah on 13 Dec 2023
Thanks for your help. Sorry its not possible for me to copy the code but I think I have narrowed it down to the line of code (quite difficult to determine exactly). The numbers aren't necessarily wrong, and don't currently cause further problems later on but before we commit changes we want to get a better understanding of what's actually happened.
X = 201x201 double
Y = 201x201 double
a 201x201 double = diff(X, [], 2)./diff(Y, [], 2)/sqrt(3)
Within this 201x201 double, a handful of the values have suddenly been calculated ever so slightly differently using the 2023b version of matlab to the 2022b version.
Steven Lord
Steven Lord on 13 Dec 2023
Can you send a MAT-file containing those two variables and that line of code to Technical Support using this link? Please also include information about your computer (if you open the System Information app the OS Name, Version, and Processor are likely the most important pieces of information)

Sign in to comment.

Tags

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!