##############
# Logistic Growth Model for Math 311
# Mark Goadrich Spring 2009
##############

# Initialize parameters
simLength = 1000
population = 100
carryingCapacity = 1000.0
growthRate = 1.7  # increase to see strange chaotic behavior
intervalSize = 1  # decrease to approximate continuous growth
growthRatePerStep = growthRate * intervalSize

# Set up file for writing output
fout = open("logistic.csv", "w")

# Iterate through simulation
for i in range(int(simLength / intervalSize)):
    population = population + growthRatePerStep * population * (1 - (population / carryingCapacity))
    fout.write("%d, %f\n" % (i, population))

# Close the file
fout.close()
