Python to MATLAB accuracy

28 次查看(过去 30 天)
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 个评论
the cyclist
the cyclist 2020-9-16
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 2020-9-18
This was very helpfull, thankyou.

请先登录,再进行评论。

采纳的回答

James Tursa
James Tursa 2020-9-16
编辑:James Tursa 2020-9-16
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 个)

类别

Help CenterFile Exchange 中查找有关 Python Package Integration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by