Bisection Search
Possible Duplicate: Using bisection search to determine 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.
Solution 1:
This is the correct one.
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)/10 * (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)
Solution 2:
This is what you need
while abs(x) > epsilon:
x = balance
for month in range(0, 12):
x = (x - ans) * (1+monthly_interest)
Post a Comment for "Bisection Search"