2

I am a relative beginner when it comes to python, and I currently am trying to figure out some python for a problem I have. I am attempting to calculate the lyapunov exponent of a bifurcation diagram I am supposed to be creating.

The equation is X_(n+1) = asin(pi x_(n)), where a = 0.9 (for when I calculate the exponent)

This is currently the code that i have set up to create an array of values becoming large.

import numpy as np
np.set_printoptions(threshold=np.nan)
import matplotlib.pyplot as plt

a = np.linspace(0,1) 
xn = np.array([.001], dtype = float)

for i in range(0,10000):
    y = a*np.sin(np.pi*xn[i])
    xn = np.append(xn,y)

plt.plot(a,xn[-1])

However, very obviously, when i plot xn, i just get a mad mess of dots instead of a bifurcation diagram. I was hoping I could get some guidance as to moving towards the correct diagram which i can hopefully use to get closer to my end goal.

Thanks for any help, I appreciate it!

JRFBSR
  • 41
  • 4
  • Change: So instead of using a = 0.9 for my diagram, I have it on a linspace from 0 to 1, which makes more sense for graphing, as I need to graph each a versus the last xn for each a. I mixed that up because I need to graph it against the lyupanov for 0.9. – JRFBSR Feb 25 '19 at 03:34

1 Answers1

0

I'm not exactly sure what you are trying to accomplish, and I don't know enough about bifurcations to really figure it out on my own, but I was able to get something that seems to work. The main caveat seems to be that if alpha starts at less than 0.158, it won't produce the right output.

import numpy as np
import matplotlib.pyplot as plt

x = [0.001]
a = np.linspace(0.2,1,100000)
for i in range(1,a.shape[0]):
    x.append(a[i]*np.sin(np.pi*x[i-1]))

fig = plt.figure(figsize=(8,4))
plt.scatter(a,x,s=0.1)

which produces the figure: bifurcation output

  • Awesome, sorry for the bad clarifications. Basically I am just trying to learn how to apply that equation into a bifurcation diagram, which you successfully did. I am wondering how you decided to use a.shape? Also, was cutting out the "y" and "xn" terms that i had just an efficiency thing? Was what i did just redundant? Thanks so much for helping, i appreciate it a ton – JRFBSR Feb 25 '19 at 04:00
  • I got rid of the `y` because it was an unnecessary middle-man; you were just assigning a value to it, then appending it before it was reset again. I used `a.shape[0]` because that is the number of samples in the linspace for `a = np.linspace(0.2, 1, 1000)`. I also started the for loop at 1 instead of 0 because we already have the first value pre-defined for `x`. I'm glad I could help! – Collin Phillips Feb 25 '19 at 04:04
  • I was wondering, if you have extra time, if you had any intuition as to why our linspace can't start at 0? Everything in this makes sense to me except that aspect, i see no reason as to why it should break down? The plot becomes a straight line, its so odd to me.** I think i see the problem if I figure it out I will reply to this comment – JRFBSR Feb 25 '19 at 04:15