Bifurcation diagram python - no image?

Viewed 55

I'm trying to make a bifurcation diagram for the following iterated map: x_n+1 = x_n * e^(r(1-x_n)).

First I defined the map:

def newmap(x,r):
    return x*math.exp(r*(1-x))

Then I tried this:

def bifurcation_diagram(rmin=0, rmax=4, r_N=2000, N_min=4000, N = 1000):
    rspace = np.linspace(rmin, rmax, r_N)
    x = 0
    rset = []
    xset = []
    for r in rspace:
        for i in range(N_min + N):
            x = newmap(x,r)
            if i > N_min:
                rset.append(r)
                xset.append(x)
    plt.figure(figsize=(16,7))
    plt.xlim((rmin,rmax))
    plt.ylim((0,5))
    plt.scatter(rset,xset,s=0.3,c='C0',linewidth=0)
    plt.xlabel(r'r', fontsize=20)
    plt.ylabel(r'$x_{end}$', fontsize=29, rotation=0)
    plt.show()

When I try bifurcation_diagram() I get a blank plot.

I'm not sure where I'm going wrong here.

1 Answers

The problem is that x=0 is a fixed point and so is x=1. If you switch x=0 to x=0.1 but otherwise leave it where it is, the first r value drives x to (what is for those values) the attracting fixed point 1. You need to put x=0.1 inside of the main loop:

for r in rspace:
    x = 0.01

(with everything else as before).

Related