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/
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.
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.
Join our real-time social learning platform and learn together with your friends!