I have a for loop which calculates a square root but for some iterations (i.e. for some values of Pos1) the expression under the square root is negative and hence the square root is impossible to calculate in the real domain and Python returns the "ValueError: math domain error" for the whole loop. Instead, I would like it to make the calculation whenever it is possible (when the expression under the square root is positive) and otherwise, print some message for example "unable to calculate sqrt" for those iterations when the value is negative.
for i in range(len(Pos1)):
theta3_1=math.sqrt(1-math.pow(((math.pow((x3-2*Pos1[0][i]),2)+math.pow((y3-2*Pos1[1][i]),2)-math.pow(L[1],2)-math.pow(L[2],2))/(2*L[1]*L[2])),2))