My code for the 2011 class Problem Set #1 question #3 seems to work for all the values that I have tried. The problem is, I don't understand why it works. I get the bisection searching is moving between the lower bound and upper bound in halfing sections and that the tolerance/epsilon is how close to the correct answer that you are willing to accept. Through trial and error I have used this concept but I don't understand how I am using it. I certainly can't explain it to someone, so if someone could explain to me what my code is doing in regards to the tolerance I would appreciate it.
Trying to hit an exact value is problematic, especially win dealing with floating point arithmetic - that is why you build in a tolerance - you get to decide how (in)accurate you want or need to be. so your code just keeps searching (using bisection) till the result is in tolerance. Usually when you use a tolerance it is 'around' the value you are trying to achieve - x plus or minus epsilon. You have implemented it as a 'negative' tolerance - x plus zero , minus epsilon: line thirty-one is your conditional for a positive error and you do not allow a tolerance; line thirty-eight is your negative error conditional and you do allow a tolerance. You are saying 'I waant to make sure i pay it off in 12 months' and 'It's ok if I pay a little xtra'. not really sure what you are asking. putting print statements in your code helps illustrate what it is doing. I see you have some in there already - sometimes formatting the print statements can give a better picture - http://dpaste.com/774925/
Join our real-time social learning platform and learn together with your friends!