Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (anonymous):

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

OpenStudy (tyteen4a03):

I don't see any notes about lecture 3.. can you link me to it?

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

Ok. I think I understand a bit more now. However, is the operator 'and' serving the same capacity as the + operator in this instance?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

I got it now. My error was in understanding exactly what the variable "ans" was in the code. Thanks for the help.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!