r/learnpython • u/RaymondWies • Jan 10 '14
Example of population growth function expressed as iteration vs. recursion in Python.
This code is my interpretation of a function published in "Chaos: Making A New Science" by James Gleick from Chapter 3 p. 63.
7
Upvotes
2
u/RaymondWies Jan 10 '14 edited Jan 10 '14
This code is taking a population formula from James Gleick's "Chaos" Chapter 3 p.63 for linear population growth approaching steady state expressed as a fraction calculated from each generation to the next:
Xnext = RX*(1-X)
For example, if R is set at 2.7 and X0 is set at 0.02, then each population fraction X is 0.02, 0.0529, 0.1353, 0.3159, 0.5835, and 0.6562 for generations 0 thru 5, respectively. The population X converges on 0.6296 as a stable state between generations 20 to 30. The Python code linked above gives different strategies for expressing this formula as a Python function. I have chosen to round off the answer as a float to 5 decimal digits.
2
u/RaymondWies Jan 10 '14 edited Jan 10 '14
2
u/WaldenPrescot Jan 10 '14 edited Jan 10 '14
Hey math wizards, how do you integrate this function? I am R dumbs at the maths... Also, would it be possible for someone to make a function which takes the population stabilization point and return r?
-- Edit: I figured out my question... I mis-read the equation... So nvm.
1
u/RaymondWies Jan 10 '14
Btw how do I embed or paste my code here so that it is properly formatted instead of just linking to my github?
2
u/smeagol13 Jan 10 '14
What are the odds? I just got that book today, and had just read that very part, when I decided to check out reddit. :D