Did I miss something on Bisection? I have watched lectures 1-3 and have completed ps0, ps1a, & ps1b successfully, but I feel like I am flying blind on ps1c... Can anyone point me towards more details/references so I can better understand bisection searches?
OK, so I have read and re-read the Wkipedia page: http://en.wikipedia.org/wiki/Bisection_method I am getting an understanding, but after a peak at the solution, But I still have questions on the ps1c assignment... Given these two statements: (high_payment - low_payment < 0.005) monthly_payment = round(monthly_payment + 0.004999, 2) Can anyone explain how you would determine that 0.005 and 0.004999 should be used?
It's tough to explain snippets out of context, particularly ones with 'magic numbers' that have no meaning out of their original context. Did you watch the video where binary search was explained? if not you may be one video away from the answer to all of your questions. Also, if your code is giving you issues, post some of it and someone will point you in the right direction. you just have to post more than 2 lines :)
Thanks for the response. I did watch Lecture 4 and Recitation 2, but bisection isn't covered any further so that it would help me tackle the problem on my own... I was referencing two lines of code that are found in ps1c_solution.py (see attached). I really wanted to tackle this one on my own, but now that I have looked at the solution so much, I am tainted... So, I would suppose it is better for me to learn what I don't understand in the solution code. I understand the logic and flow of the program, but what I cannot sort out are the 'magic numbers' found on lines 27 and 33. Any assistance would be appreciated.
round(number[, ndigits]) Return the floating point value number rounded to ndigits digits after the decimal point. If ndigits is omitted, it defaults to zero. The result is a floating point number. Values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done away from 0 (so. for example, round(0.5) is 1.0 and round(-0.5) is -1.0). Note The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float. See Floating Point Arithmetic: Issues and Limitations for more information. That made little sense until I re-read: "Values are rounded to the closest multiple of 10 to the power minus ndigits" I thought I could give you an example in a proof and realized I lost it again. https://docs.python.org/2/library/functions.html#round See if this seems right. money is the most understood example and applies to this example. Why use .0049 vs. .0051? SUBTRACTING .0049 from .01 WILL LEAVE A .0061 AND Have the opportunity to round up when .0051 would never have the ability to round up. Also we are rounding up one cent, the number may be designed to only round when it is very close or only round at .0099. anything less will be truncated. ok i hope that helps. good question.
Join our real-time social learning platform and learn together with your friends!