Created
November 2, 2013 15:24
-
-
Save mgualt/7280078 to your computer and use it in GitHub Desktop.
One simple improvement to the code I gave in Assignment 8 would be to define the function as below. In this way, f actually takes input which is an ordered pair (c,x), and outputs another ordered pair (c, x^2 + c). Then when building the long term values list, we get somewhat simpler code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f((c,x)): | |
return (c,x^2 + c) | |
def LTV(c): | |
"returns last 50 results from iterating f 500 times beginning with (c,0)" | |
points=[(c,0)] | |
for i in range(500): | |
newpoint = f(points[-1]) | |
points.append(newpoint) | |
return points[-50:] | |
def LTVInterval(a,b): | |
"returns long term vals for 1000 choices of c between a and b" | |
data=[] | |
for i in range(1000): | |
c = a + i*(b-a)/1000 | |
data.extend(LTV(c)) | |
return data | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment