Created
November 3, 2013 18:29
-
-
Save myuon/7293230 to your computer and use it in GitHub Desktop.
periodic doubling
https://pbs.twimg.com/media/BYKrHfpCEAABToE.png:large
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
#! /usr/bin/python3.3 | |
#-*- coding:utf-8 -*- | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import random | |
from timeit import Timer | |
import time | |
def recur(n, x, func): | |
y = x | |
for _ in [0]*n: | |
if not -100000 <= y <= 100000: return y | |
y = func(y) | |
return y | |
def recur_list(n, x, func, initp=1): | |
y = initp | |
for i in range(n): | |
y = func(y) | |
yield y | |
# y = μx(1-x) | |
# 0 < x < 1 | |
# 各μを一つ決め、適当なxをfunctionに対してiterateさせる | |
# iterateの最初100回程度は切り捨て、残りをプロットする | |
def quadratic(mu, x): | |
return mu * x * (1 - x) | |
def fix_mu(mu, func): | |
def run(x): | |
return func(mu, x) | |
return run | |
def main(): | |
mu = np.arange(1.0, 5.0, 0.005) | |
#x = np.arange(0.0, 1.01, 0.01) | |
x = 0.483281 | |
for m in np.nditer(mu): | |
q = fix_mu(m, quadratic) | |
start_point = recur(100, x, q) | |
# print(x,m,start_point) | |
for p in recur_list(10, x, q, initp=start_point): | |
if not 0 <= p <= 1: break | |
plt.plot(m, p, 'b,') | |
plt.xlabel('mu') | |
plt.ylabel('y(100-1000 times)') | |
plt.show() | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment