0

I want to draw a Bifurcation diagram of quadratic map in python. Basically its a plot of x_{n+1}=x_n^2-c and it should look like http://static.sewanee.edu/Physics/PHYSICS123/image99.gif

But I am newbie so I am not sure do I make it right.

My code

import numpy as n
import scipy as s
import pylab as p

xa=0.252
xb=1.99

C=n.linspace(xa,0.001,xb)
iter=100
Y=n.zeros((len(X),iteracje))
i=1
Y0=1
for Y0 in iter:
    Y(i+1)=Y0^2-C

for Y0 in iter:
        Y(i+1)=Y0^2-C

p.plot(C,Y)
p.show()

My problem is that I don't know how properly write these for loop properly.

wiedzminYo
  • 531
  • 4
  • 11
  • 24
  • can you explain what you want the program to be doing? What are your `for` loops intended to do? – Joel Jan 05 '15 at 11:40
  • Genuine question: how have you decided that practically the first Python program you write, before learning any of the syntax of that language, will be a bifurcation diagram of quadratic map? – xnx Jan 05 '15 at 11:56
  • Becouse I need it for my research. – wiedzminYo Jan 05 '15 at 21:58

1 Answers1

3

Here is some modified code (partial explanation below)

import numpy as n
import scipy as s
import pylab as p

xa=0.252
xb=1.99

C=n.linspace(xa,xb,100)
print C
iter=1000
Y = n.ones(len(C))

for x in xrange(iter):
    Y = Y**2 - C   #get rid of early transients

for x in xrange(iter): 
    Y = Y**2 - C
    p.plot(C,Y, '.', color = 'k', markersize = 2)


p.show()

First, the linspace command had the wrong format. help(s.linspace) will give you insight into the syntax. The first two arguments are start and stop. The third is how many values. I then made Y a numpy array of the same length as C, but whose values were all 1. Your Y0 was simply the number 1, and it never changed. Then I did some iteration to get past the initial conditions. Then did more iteration plotting each value.

To really understand what I've done, you'll have to look at how numpy handles calculations with arrays.

Joel
  • 22,598
  • 6
  • 69
  • 93
  • Thank you,this is very helpful.And you are right I have to go deep in numpy doc,becouse I will use it for long time. – wiedzminYo Jan 05 '15 at 12:00