For the lecture 3 python notes, I'm having a hard time following the bisection search code that finds the square roots. I don't understand the while condition statement "while abs(ans**2 - x) >= epsilon and ans <= x:", specifically how the "epsilon" variable is working within the statement
I don't see any notes about lecture 3.. can you link me to it?
if answer squared is equal to x (plus or minus epsilon) then you have found your answer. if (x - epsilon) < answer squared < (x + epsilon) then you have found your answer epsilon is used to specify a tolerance for your calculations. how precise do you want your answer to be? higher precision will take more iterations. also floating point arithmetic is inaccurate - some numbers cannot be represented in binary; if you do not specify a tolerance the algorithm may never find a solution. the 2008 course had a lecture where floating point math errors were discussed - i don't know about the 2011 course.
Ok. I think I understand a bit more now. However, is the operator 'and' serving the same capacity as the + operator in this instance?
and is a logical/boolean operator True and True == True True and False == False False and False == False http://docs.python.org/library/stdtypes.html#boolean-operations-and-or-not
I got it now. My error was in understanding exactly what the variable "ans" was in the code. Thanks for the help.
Join our real-time social learning platform and learn together with your friends!