6.00:
Introduction to Computer Science and Programming
Problem Set 2
Handed out: Tuesday, February 19, 2008.
Problem #1 Due: 11:59pm, Friday, February 21, 2008.
Problem #2 Due: 11:59pm, Tuesday, February 26, 2008.
This problem set will practice using the technique of successive approximation to solve tough problems.
You may work with other students. However, each student should write up and hand in his or her assignment separately. Be sure to indicate with whom you have worked. For further detail, please review the collaboration policy as stated in the course information handout.
Download these files so that they are together in the same directory.
A university (or maybe it was an institute) decided that it wants to go out of business in y years.
It has an endowment of eInit dollars. The annual return on the endowment is eGrowth%; (If eGrowth is negative, then the endowment shrinks instead of grows.) The university has n students and its annual tuition is t dollars. Tuition increases by tGrowth% each year; in other words, during the first year, tuition is tInit dollars, and it increases by tGrowth% each year after that.
Each year, the endowment is drawn down to supply financial aid packages that sum to subsidy% of the total tuition. All other expenses of the university are covered by the tuition collected, with no tuition left over. Therefore, at the start of year i+1, the endowment ei+1 is equal to
ei+1 = (ei-n*ti*subsidy/100.0)*(1+(eGrowth/100.0))
and the tuition for year i+1 is given by
ti+1 = ti*(1+(tGrowth/100.0))
Problem 1.
Write and test the function
futureEndowment(n, eInit, tInit, eGrowth, tGrowth, subsidy, y)
that computes the value of the endowment after y years. If at some point the endowment is too small to pay all student subsidies, futureEndowment() should return None. In other words, if after some year i < y, ei >= n*ti*(subsidy/100)
Use test_ps3.py to test your implementation of futureEndowment(). Running test_ps3.py will call your futureEndowment() with some example parameters and test that your answers are in the right ballpark.
Problem 2.
Write and test the function
findMinEndowmentGrowth(n, eInit, tInit, tGrowth, subsidy, y, epsilon)
that computes the minimum eGrowth needed so that the endowment will be sufficient to cover subsidy% of the total tuition for y years. The school has n students. Note that at the end of the y year period, the endowment should be within epsilon of zero, and the university will then shut its doors.
Use test_ps3.py to test your implementation of findMinEndowmentGrowth(). Running test_ps3.py will call your findMinEndowmentGrowth() implementation with some example parameters and test that your answers are not in Yankee Stadium. This file also contains a function runFindMinEndowmentGrowth() that might be helpful to test your code. It runs your implementation of findMinEndowmentGrowth() and prints the returned answer to 20 decimal places.
Hints:
At the start of each year the endowment must be large enough to pay the subsidy for all students' tuitions. (In other words, if futureEndowment() returns None, then eGrowth is too small.)
There will be some cases that eInit is large enough so that eGrowth can be negative. So eGrowth can take values in the range [-100.0, 100.0].
Save your code in ps3.py Do not ignore this step or save your files with different names!
At the start of each file, in a comment, write down the number of hours (roughly) you spent on the problems in that part, and the names of the people you collaborated with. For example:
# Problem Set 3 # Name: Jane Lee # Collaborators: John Doe # Time: 3:30 # ... your code goes here ...
To submit a file, upload it to your workspace. If there is some error uploading to your workspace, email the file to 6.00-staff [at] mit.edu.
You may upload (or email) new versions of each file until the 11:59pm deadline, but anything uploaded after that will be ignored.