[Python] Coding a bifurcation diagram

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I was wondering what was wrong with my code as I keep getting a weird but similar result to the actual bifurcation diagram. I am using the iterative equation xn+1 = xn * r(1-xn).

    Here is my code:

    import numpy as np
    import matplotlib.pyplot as plt
    from functools import lru_cache

    @lru_cache(maxsize = 1000)
    def bifunc():
    R_val = []
    X_val = []
    R = np.linspace(0.5,4,1000)
    for r in R:
    x = 0.5
    for iterations in range(1001):
    x = x*r*(1-x)
    R_val.append(r)
    X_val.append(x)

    plt.plot(R_val, X_val, ls = '', marker = ',')
    plt.show()

    bifunc()


    Here is the image that keeps coming up: [​IMG]

    Any help would be appreciated. Thank you.

    Continue reading...

Compartilhe esta Página