MATLAB Answers

Python to MATLAB accuracy

8 views (last 30 days)
Hi, so I am translating code from Python to MATLAB and I am using very presice numbers in my calculations.
I am getting very small differences which have a very large impact on the final result. I need the MATLAB code to function the same as the Python.
For example, the numbers from Python are: mu20= 10.1859163332|80940 & mu02= 10.1859163332|81872
And the supposedly same numbers in MATLAB are: mu20 =10.1859163332|72582 & mu02 =10.1859163332|72116
As you can see the last 5 numbers in both are different. Is there anyway to make it so that they are the same in MATLAB as they are in Python?
Cheers,
Ollie

  2 Comments

the cyclist
the cyclist on 16 Sep 2020
For your current python calculation, do you have reason to believe that those trailing 5 digits are meaningful? If you are doing the python version as 64-bit floating-point, then I would assume they are not. It seems possible to me that you have a case of false precision.
And if that is the case, and if differences beyond 12 digits of precision are causing very large impact on your final result, then I'd question whether your final result is meaningful.
If your python result is such that you know all of those digits are meaningful, then 64-bit MATLAB (or 64-bit anything) calculations are not going to be able to replicate it.
Oliver Horrobin
Oliver Horrobin on 18 Sep 2020
This was very helpfull, thankyou.

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 16 Sep 2020
Edited: James Tursa on 16 Sep 2020
Probably not. The trailing bits of floating point calculations in general can't be trusted. It you change the order of the calculations even slightly, differences in results should be expected. Depending on what your calculations are, you may not be able to control this order of calculations. What exactly are the calculations you are doing? Are you sure you are starting with the exact same values in both cases? Any algorithm that depends on the trailing bits of floating point calculations raises red flags ... is your algorithm and data really reliable to that precision?

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!