0

I need to evaluate the following equation:

enter image description here

I have the following parameters values:

C_gamma = 8.846E-05 m/GeV3
Gamma = 11741.707101355101
beamEnergy = 6.0E9 #eV
I2 = 0.2803660599555248
E0 = (beamEnergy/Gamma)

I tried the following equation:

U0 = (beamEnergy/Gamma)**4 * I2 * (8.846E-14)/(2*(np.pi))

The value that i got is 269.13646021955805 MeV which is much more high that what i expected (~4.66 Mev) My question is how to convert the parameter C_gamma = 8.846E-05 m/GeV3 unit to obtain the expected value ?

Esalah
  • 27
  • 1
  • 5
  • Also: floating math for very small / big values is not exact: see [Is floating math broken](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Patrick Artner Dec 07 '21 at 08:33
  • 1
    I used 8.846E-14 to get rid of the Gega, when i used 8.846E-5 the value is still not as expected, For the name error its just a mistake in writing the question, i edited it – Esalah Dec 07 '21 at 08:35
  • 1
    Are there maybe some typos in your formulas? I've tried the equations as they're stated and I'm getting something different. What does the notation GeV3 mean? GeV = 10^9 eV of course, but do you mean GeV^3 ? Thanks for any clarification. – Robert Dodier Dec 07 '21 at 20:33
  • @RobertDodier Could you please mentioned the value that you got ? For the GeV3 meaning its not Clearfield in the reference unfortunately so i had to try all the possibilities but i still couldn't reach the expected value – Esalah Dec 09 '21 at 07:46
  • I don't remember exactly, but I think I got the same digits as you reported, but off by a factor of 10^something where something = 14 or -14 or something like that. Can you give a link to a reference about that formula? I'm interested to try to sort out the interpretation. – Robert Dodier Dec 09 '21 at 17:30

1 Answers1

0

With float arithmetics you should always have the fact of Is floating math broken - which is documented here: python.org "15. Floating Point Arithmetic: Issues and Limitations" in the back of your mind.

Especially if you handle very tiny and very big numbers together.

You have numbers that are 1e36 apart ... your result differs by a factor of 50.

Float math does not handle very big/very small values very good - especially not if you mix them - it introduces rounding errors.


Edit:

Conversion to fractions of the initial values does lead to a difference, but it is tiny - so probably not broken floating math at work here:

from fractions import Fraction
from math import pi

C_gamma = 8.846E-14
Gamma = 11741.707101355101
beamEnergy = 6.0E9 
I2 = 0.2803660599555248
E0 = (beamEnergy/Gamma)

U0 = E0**4 * I2 * C_gamma/(2*pi)  

print(f"{U0:20.15f}")


fr_C_gamma = Fraction.from_float( 8.846E-14)
fr_Gamma = Fraction.from_float(11741.707101355101)
fr_beamEnergy = Fraction.from_float(6.0E9 )
fr_I2 = Fraction.from_float(0.2803660599555248)
fr_E0 = fr_beamEnergy/fr_Gamma

fr_U0 = fr_E0**4 * fr_I2 * fr_C_gamma/(2*pi)  

print(f"{fr_U0:20.15f}")

Output:

269136460.219558060169220  (float) 
269136460.219558119773865 (Fractions)

So mabye you should go over the initial formula again and see if that has some problems - as pointed out by Robert Dodier in a comment your formula contains m/GeV3 - which may be Volt cubed?

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
  • Thanks you, but is there any solution to solve such problem in Python ? – Esalah Dec 07 '21 at 10:21
  • @Esalah - read the info on python.org, linked in my answer. It gives you some pointers what to do to aleviate your problem. – Patrick Artner Dec 07 '21 at 10:25
  • 1
    I dunno if I agree with this analysis. Since the operations are all multiplications or divisions, the relative errors get multiplied too. Assuming the numbers are accurate to the number of digits shown, the accuracy of the result is limited by the least accurate term, which is (6.0 +/- something)^4 where something < 0.05 since two digits are reported. That's less than (6.05/5.95)^4 = 1.069. – Robert Dodier Dec 07 '21 at 20:25
  • 1
    I guess it would be a problem if the magnitude of the terms was bumping into the limits of what's representable, but I guess I'm not seeing that either. Assuming numbers are double floats, the range is something like 10^(+/- 308). I guess one would have to consider it more carefully if the numbers were single floats, but that's not the default float representation in Python, is it? – Robert Dodier Dec 07 '21 at 20:29
  • @RobertDodier I agree - I converted the floats to fractions and thee is a difference in results but it is negligable: `269136460.219558060169220 (float) vs. 269136460.219558119773865 (Fractions)` – Patrick Artner Dec 07 '21 at 22:44