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

Hello, in lecture 3, I'm having trouble understanding why "ans <= x" was the terminating condition and not abs(ans**2 - x) >= epsilon. This is the code he gave: http://dpaste.com/1543194/

OpenStudy (anonymous):

Hi, it is because while all values will terminate when ans increases by 0.0001 to value x, there are certain values where this method will not produce the square root(where abs(ans**2 - x) >= epsilon). I think it is explained at the start of the next lecture where it will become clearer to you what those values are.

OpenStudy (anonymous):

To add to the above my understanding is that abs(ans**2 - x) >= epsilon can act as a terminating condition but if it fails (remember Guttag mentions that program does not work for all positive values) then ans <= x will terminate program. As I am a complete newbie here hope this is correct. Also thinking that square root of some fractions might lead to this situation. someone should correct me if I am wrong.

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!