I'm using np.random.uniform to avoid using a for loop that would be very inefficient for my code, I run a UDF called calculation inside of a while loop, that section of the code looks like this:
lower = 60
upper = 232
step = 0.0001
while (upper - lower) >= step:
xn = round(np.random.uniform(lower, upper), 5)
# xn = random in Neutral_axis_depth
if abs(calculations(angle, xn)[2]) > 1:
if calculations(angle, xn)[2] < 0:
print(xn, angle)
upper = xn
print(upper, lower, calculations(angle, xn)[2])
else:
print(xn, angle)
lower = xn
print(upper, lower, calculations(angle, xn)[2])
else:
print('for upper', upper, ' and lower', lower, 'answer is', calculations(angle, xn))
All variables are defined.
So basically what I'm doing is updating the values of upper and lower in each iteration to shorten the range in which np.random.uniform works. The problem begins when the loop is really close to give the answer. I want: an xn that will make abs(calculations(angle, xn)[2]) < 1 (expressed by the else statement in the while loop), for example:
- for a defined angle= 0.000015, the xn I'm looking for is 73.1998 (found it manually with a simpler version of the code), BUT here, xn = round(np.random.uniform(lower, upper), 5) gets stuck between 73.19951(lower) and 73.20001(upper), never getting to 73.1998.
I would like to know why and how to solve this
Aucun commentaire:
Enregistrer un commentaire