A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

I need help with Problem 4 from PS4. I cannot figure out what my if statement should be in the binary search. If I do the problem manually, knowing the answer it's easy as I know when to assign the guess from low to high. I get the correct answers for parts 1-3, so I know that's not the issue.

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    def findMaxExpenses(salary, save, preRetireGrowthRates, postRetireGrowthRates, epsilon): low = 0 est_high = nestEggVariable(salary, save, preRetireGrowthRates) high = est_high[-1] # amount of money at start of retirement guess = (low + high)/2.0 retirement_list = postRetirement(high, postRetireGrowthRates, guess) money_end_retirement = retirement_list[-1] print money_end_retirement while abs(money_end_retirement) > epsilon: print guess # printing the expenses guess each iteration if ?????: high = guess guess = (low + high) / 2.0 retirement_list = postRetirement(high, postRetireGrowthRates, guess) money_end_retirement = retirement_list[-1] else: low = guess guess = (low + high) /2.0 retirement_list = postRetirement(high, postRetireGrowthRates, guess) money_end_retirement = retirement_list[-1] print "final estimate is ", guess Am I on the right track? Any help is greatly appreciated! :)

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, you're on the right track. Figure out how your guess affects the money_end_retirement, and you will know what to check for in your IF statement.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks Aslander!! Turns out my original assumption of if money_end_retirement < 0: was correct, but I had the wrong value for my savings in postRetirement function. It should've been the money at the start of retirement. It threw me off!

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.