Reputation: 661
I have a problem with the following code :
- k_cav*((Tcav*b**3*Pr/((T3+T2)*v**2))**4.42)**0.091/b
It throws the error shown in the title, but I have ensured that the base of the fractional power (0.091) is positive for all possible value. Tcav = abs(T3-T2), b = 0.01, Pr = 0.72, v = 1.34*10**(-5)
, T3 and T2 are temperatures in kelvin around 285.
It should be mentioned that the calculation is a part of a huge calculation, which is repeated several times to determined several temperatures via the Newton–Raphson numerical root finding method, and that the error only occurs after several iterations.
Can any body help me with a solution on this problem. I have no clue about what to do about it.
Upvotes: 0
Views: 1477
Reputation: 20311
Python 2 consider the precedence of the negative (it is resolved in Python 3). Check this out, a similar issue.
Upvotes: 0
Reputation: 59426
I propose to use try
/except
to catch the error and then print out the variable's values. This way you can be sure to see the culprit:
try:
computedValue = - k_cav*((Tcav*b**3*Pr/((T3+T2)*v**2))**4.42)**0.091/b
except ValueError:
print k_cav, Tcav, b, Pr, T3, T2, v
raise
doWhateverYouDoWith(computedValue)
Upvotes: 1