Hello, I completed two first problems from problem set 2 but cannot comprehend what to do with the last one? any help?
Just check the bisection method in the wiki page and try to apply that to the problem at hand. Come back with specific questions and we will help!
I tried to read and understoo the idea but I have no idea what to with my code. I keep getting errors or output is nonsensical...
This is code for second problem...it seems like I can use it for third one but my modifications resulted in failures...I have been trying to kill this problem for six hours today.. payment = 10 newBalance = balance while balance > 0: for month in range(1,13): newBalance = (newBalance - payment)*(1 + annualInterestRate/12) if newBalance <=0: break if newBalance <= 0: balance = newBalance else: newBalance = balance payment = payment+10
I think the basic idea behind the bisection method is to have upper and lower bounds and use the mean value as the monthly payment. Depending on the end result of the balance at the end of the 12 months you should reset the upper or the lower bound and repeat. At some point you will come up with the correct figure. Does this help at all?
I completely understand idea but my problem is that I cannot produce the right code..tried to use print for debugging but with any fortune..
the code above doesn't use the bisection method at all. where is your attempt? you know that we can provide the solution before the deadline right???
we can't I meant!
Let's see if I can help without saying too much. Your 'payment' instead of being increments of 10 is going to be the average of 'upper' and 'lower' bounds defined in the problem. Depending on the resulting balance, your lower or upper bound is going to change to your previous 'payment'. One other thing that messed me up for a bit is that you will need to a 'round' to 2 decimal places before your 'if' because you want to come with .01 not .00000000..00001 Hope this helps.
That should say 'come within .01'
here is a bisection algorithm for finding square roots http://dpaste.com/811787/ lines 17 - 25 would be very similar for the problem you are working on
Thank you all, I solved the problem. I guess fresh head in the morning is a lot better than coding six hours straight :)
Join our real-time social learning platform and learn together with your friends!