anonymous
  • anonymous
I'm having some trouble with Problem Set 1, Part 3. The first two parts were easy, but I'm a little confused on how to implement bisection searching. I understand the concept well, but not sure what conditional to use to know when I've found the minimum monthly payment (mmp). I have looked at a few different examples and tested them, but I am getting incorrect answers. I thought perhaps the problem was that the floats were not limited to two decimal places, but adding round() to the upper and lower bounds seems to result in an infinite loop. Using an example from http://stackoverflow.com/questions/12820003/bisection-search?rq=1
MIT 6.00 Intro Computer Science (OCW)
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
This is my output: Enter the outstanding balance on your credit card: 320000 Enter the annual interest rate as a decimal: .2 RESULT Monthly payment to pay off debt in 1 year: $26666.6673641 Number of months needed: 11.9999996862
1 Attachment
anonymous
  • anonymous
I used: if balance <= 5 and balance > 0: print "**if" print "Your minimum payment is:", guess print balance break elif balance > 0: print "**elif, balance is to high, guess being tested was to low" print "current lowerGuess", lowerGuess print "current guess", guess lowerGuess = guess print "new lowerGuess", lowerGuess guess = (higherGuess + lowerGuess)/2 print "new guess", guess else: print "**else, balance was to low, guess being tested was to high" print "current higherGuess", higherGuess print "current guess", guess higherGuess = guess print "new higherGuess", higherGuess guess = (higherGuess + lowerGuess)/2.0 print "new guess", guess and it seems to be working. the print statements are just in there to show me what's happening. it basically says that getting the balance down to $5 or less is good enough.
anonymous
  • anonymous
is it in Python? @kpennington89

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Yes. I am getting closer. I did realize an error I didn't notice before: I was using the wrong equation to calculate remaining balance. The assignment is to find the minimum monthly payment to the nearest cent, so I would prefer to do that than to the nearest $5. Here is my code at the moment: while mmp*12 - bal >= 0.01: remain = bal for month in range(0,12): remain = round(remain * (1+monthly) - mmp,2) #print "\nmonth: " + str(month+1) #print "remaining balance: " + str(remain) if remain < -0.2: #guess too high upper = mmp mmp = round((lower+upper)/2,2) print "\nremaining balance: " + str(remain) print "mmp = " + str(mmp) print "lower: " + str(lower) print "upper: " + str(upper) elif remain > 0.01: #guess too low lower = mmp mmp = round((lower+upper)/2.0,2) print "\nremaining balance: " + str(remain) print "mmp = " + str(mmp) print "lower: " + str(lower) print "upper: " + str(upper) else: break print "\nRESULT\nMonthly payment to pay off debt in 1 year: $" + str(mmp) print "Number of months needed: " + str(round(bal/mmp,2)) Which results in an accurate answer for the first test case: Enter the outstanding balance on your credit card: 320000 Enter the annual interest rate as a decimal: .2 RESULT Monthly payment to pay off debt in 1 year: $29643.05 Number of months needed: 10.8 BUT the result for the second test case is off by $0.01. Caused by using round()? : Enter the outstanding balance on your credit card: 999999 Enter the annual interest rate as a decimal: .18 RESULT Monthly payment to pay off debt in 1 year: $91679.9 Number of months needed: 10.91 I also noticed that in his handout the # of months required is not accurate for the minimum monthly payment in his results. It says 12 for both when really it rounds up to 11 months. I suppose these results are good enough! Thanks all for your help!

Looking for something else?

Not the answer you are looking for? Search for more explanations.