bifurcation diagram with python

2024/10/14 1:09:58

I'm a beginner and I don't speak english very well so sorry about that. I'd like to draw the bifurcation diagram of the sequence : x(n+1)=ux(n)(1-x(n)) with x(0)=0.7 and u between 0.7 and 4.

I am supposed to get something like this :

https://i.stack.imgur.com/T4gyF.png

So, for each value of u, I'd like to calculate the accumulation points of this sequence. That's why I'd like to code something that could display every points (u;x1001),(u;x1002)...(u;x1050) for each value of u.

I did this :

import matplotlib.pyplot as plt
import numpy as np
P=np.linspace(0.7,4,10000)
m=0.7
Y=[m]
l=np.linspace(1000,1050,51)
for u in P:X=[u]for n in range(1001):m=(u*m)*(1-m)break for l in range(1051):m=(u*m)*(1-m)Y.append(m)
plt.plot(X,Y)
plt.show()

And, I get a blank graphic.

This is the first thing I try to code and I don't know anything yet in Python so I need help please.

Answer

There are a few issues in your code. Although the problem you have is a code review problem, generating bifurcation diagrams is a problem of general interest (it might need a relocation on scicomp but I don't know how to request that formally).

import matplotlib.pyplot as plt
import numpy as np
P=np.linspace(0.7,4,10000)
m=0.7
# Initialize your data containers identically
X = []
Y = []
# l is never used, I removed it.
for u in P:# Add one value to X instead of resetting it.X.append(u)# Start with a random value of m instead of remaining stuck# on a particular branch of the diagramm = np.random.random()for n in range(1001):m=(u*m)*(1-m)# The break is harmful here as it prevents completion of# the loop and collection of data in Y for l in range(1051):m=(u*m)*(1-m)# Collection of data in Y must be done once per value of uY.append(m)
# Remove the line between successive data points, this renders
# the plot illegible. Use a small marker instead.
plt.plot(X, Y, ls='', marker=',')
plt.show()

Also, X is useless here as it contains a copy of P.

https://en.xdnf.cn/q/69467.html

Related Q&A

How do I use nordvpn servers as python requests proxies

Dont ask how, but I parsed the server endpoints of over 5000 nordvpn servers. They usually are something like ar15.nordvpn.com for example. Im trying to use nordvpn servers as request proxies. I know i…

Python Proxy Settings

I was using the wikipedia module in which you can get the information that is present about that topic on wikipedia. When I run the code it is unable to connect because of proxy. When I connected PC to…

Docker - Run Container from Inside Container

I have two applications:a Python console script that does a short(ish) task and exits a Flask "frontend" for starting the console app by passing it command line argumentsCurrently, the Flask …

Way to run Maven from Python script?

(I am using Windows.)I am trying to run maven from a python script. I have this:import subprocessmvn="C:\\_home\\apache-maven-2.2.1\\bin\\mvn.bat --version" p = subprocess.Popen(mvn, shell=Tr…

Why does testing `NaN == NaN` not work for dropping from a pandas dataFrame?

Please explain how NaNs are treated in pandas because the following logic seems "broken" to me, I tried various ways (shown below) to drop the empty values.My dataframe, which I load from a C…

Python dynamic import methods from file [duplicate]

This question already has answers here:How can I import a module dynamically given its name as string?(10 answers)How can I import a module dynamically given the full path?(37 answers)Closed last yea…

Python list does not shuffle in a loop

Im trying to create an randomized list of keys by iterating:import randomkeys = [1, 2, 3, 4, 5] random.shuffle(keys) print keysThis works perfect. However, if I put it in a loop and capture the output:…

Python extract max value from nested dictionary

I have a nested dictionary of the form:{2015-01-01: {time: 8, capacity: 5}, 2015-01-02: {time: 8, capacity: 7},2015-01-03: {time: 8, capacity: 8} etc}The dictionary is created from a csv file using dic…

Exponential Decay on Python Pandas DataFrame

Im trying to efficiently compute a running sum, with exponential decay, of each column of a Pandas DataFrame. The DataFrame contains a daily score for each country in the world. The DataFrame looks lik…

TensorFlow - why doesnt this sofmax regression learn anything?

I am aiming to do big things with TensorFlow, but Im trying to start small. I have small greyscale squares (with a little noise) and I want to classify them according to their colour (e.g. 3 categories…