1

I am working in google collab and I encountered this problem:

<ipython-input-23-1d1d2f123229>:47: RuntimeWarning: invalid value encountered in power f2 = lambda x: 2 * x * np.log(10) - C + (a* (((X1 - x))**(3.24)))

I refered to this post here: NumPy, RuntimeWarning: invalid value encountered in power

and tried all the recommedation including using np.pow and abs however it still provides the error.

My code snippet is as follows

C = 3.20 #from LEO textbook
a = 0.1610
m = 3.24
X1 = 2.49
X0 = 0.1464
delta0 = 0.14
X = lambda p: np.log10(beta_gamma(p))

f2 = lambda x: 2 * x * np.log(10) - C + (a* (((X1 - x))**(3.24)))
#f2 = lambda x: 2 * x * np.log(10) - C + (a * np.real((X1 - x) ** 3.25))
f3 = lambda x: 2 * x * np.log(10) + C
delta_full = lambda x: np.piecewise(x, [x < X0 , x >= X0], [f1, f2])

...

ps = np.logspace(2, 8, 10000) # MeV

for pi in range(0, len(ps)):
    ...
    beta_gammas[pi] = beta_gamma(ps[pi])
    density_correction[pi] = delta_full(ps[pi])
    ...


Any help would be appreciated

EDIT 1

Upon further inspection it seems that the main error occurs in this line of code :

delta_full = lambda x: np.piecewise(x, [x < X0 , x >= X0], [f1, f2])

as it fails here. My assumption was due to complex numbers however it still works for values below X0. I have added more code for reference.

Some_user
  • 11
  • 3

0 Answers0