Mar-10-2018, 06:06 PM
(This post was last modified: Mar-10-2018, 06:06 PM by Turbotanten.)
Hi, I'm new to Python so please be gentle
I don't know seriously what is wrong with my code
Here's my code
Since
But instead I get
I get 1 + 1 j. And If I remove the to the power of 1/4 it works and I get -4
So why do
give me error?
I don't know seriously what is wrong with my code
Here's my code
1 2 3 4 5 6 7 8 9 10 11 |
import numpy as np def epsilon(t): epsilon = ( 1 - np.exp( - pow (t, 4 ))) return epsilon def r(t): r = pow ( (epsilon(t) - 16 ) / 4 , 1 / 4 ) return r print (r( 0 )) |
epsilon(0) = 0
, I'd expect (analytically) to get r = (-16/4)^(1/4) = (-1)^(1/4)*sqrt(2) = exp(i pi /4)*sqrt(2) = 1 + 1 iBut instead I get
Error:RuntimeWarning: invalid value encountered in double_scalars
r = pow((4 * epsilon(t) - 16) / 4, 1/4)
nan
I've tried to find the error. If I print epsilon(0)
I get 0 as expected, and If i set epsilon(0)
manually like1 2 3 4 |
def r(t): r = pow ( 0 - 16 ) / 4 , 1 / 4 ) return r print (r( 0 )) |
1 2 3 4 5 6 7 8 9 10 11 |
import numpy as np def epsilon(t): epsilon = ( 1 - np.exp( - pow (t, 4 ))) return epsilon def r(t): r = (epsilon(t) - 16 ) / 4 return r print (r( 0 )) |
1 2 3 4 5 6 7 8 9 10 11 |
import numpy as np def epsilon(t): epsilon = ( 1 - np.exp( - pow (t, 4 ))) return epsilon def r(t): r = pow ( (epsilon(t) - 16 ) / 4 , 1 / 4 ) return r print (r( 0 )) |