title: Bisection search
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12804670/using-bisection-search-to-determine">Using bisection search to determine</a>  </p>
  </blockquote>
  
  
  
  <p>I have posted other thread but it did not receive answers thus i'm trying to provide some of my work to make more clear.</p>
  
  <p>I need to use bisection method to determine monthly payment in order to pay off debt in one year exactly.</p>
  
  <p>Here's some code:</p>
  
  <pre><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 &gt;= epsilon:
      for month in range(0, 12):
          balance = (originalBalance - min_payment) * (1+monthly_interest)
  
      if balance &lt; 0:
          low = min_payment
      elif balance &gt; 0:
          high = min_payment
          min_payment = (high + low)/2.0
  print "lowest payment: " + str(balance)
  </code></pre>
  
  <p>However, I receive very way off answer: 298222.173851</p>
  
  <p>My friend told me that correct answer is : 29157.09</p>
  
  <p>Which is a lot lower than my...I guess the problem is in rounding(which I did not do yet) and preserving the balance after every looping and resetting it if balance is over 0. I cannot figure out how to attempt this problem and please, help someone :)</p>