Skip to content

Instantly share code, notes, and snippets.

@kdungs
Created April 8, 2014 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdungs/10204975 to your computer and use it in GitHub Desktop.
Save kdungs/10204975 to your computer and use it in GitHub Desktop.
Implementation of logistic map in Python. Used for comparing the runtime to the C++11-solution.
#!/usr/bin/env python
from itertools import repeat
import numpy as np
NUM_RUNS = 1000
def logistic_map(xn, r):
return r * xn * (1 - xn)
def calculate_fixpoint(x0, r):
xN = x0
for _ in repeat(None, NUM_RUNS):
xN = logistic_map(xN, r)
return xN
def write_to_file(r, xs):
np.savetxt('./data/{}.txt'.format(r), xs)
for r in np.arange(0, 4, 0.1):
xs = np.linspace(0.1, 1, 1000)
write_to_file(r, calculate_fixpoint(xs, r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment