Using search in half to determine

I published another thread, but it did not receive any answers, so I am trying to provide some of my work in order to make it more understandable.

I need to use the bisection method to determine the monthly payment in order to pay off the debt for the year accurately.

Here is the code:

originalBalance = 320000 annualInterestRate = 0.2 monthly_interest = annualInterestRate / 12 low = originalBalance/12 high = (originalBalance*(1 + monthly_interest)**12)/12 epsilon = 0.01 min_payment = (high + low)/2.0 while min_payment*12 - originalBalance >= epsilon: for month in range(0, 12): balance = (originalBalance - min_payment) * (1+monthly_interest) if balance < 0: low = min_payment elif balance > 0: high = min_payment min_payment = (high + low)/2.0 print "lowest payment: " + str(balance) 

However, I get a very answer: 298222.173851

My friend told me the correct answer: 29157.09

Which is much lower than mine ... I think the problem is rounding (which I have not done yet) and maintaining balance after each cycle and resetting it if the balance is 0. I cannot figure out how to try this problem and please help someone something :)

0
python
source share
2 answers

This is the key:

 while abs(x) > epsilon: x = balance for month in range(0, 12): x = (x - ans) * (1+monthly_interest) 
0
source share

remember to round to two decimal places, otherwise MITx will not accept the answer

0
source share

All Articles