Question

In: Computer Science

bifurcation diagram for 1000 iterations code with graf in pythone

bifurcation diagram for 1000 iterations code with graf in pythone

Solutions

Expert Solution

we will be using NumPy and matplotlib for bifurcation diagram as it is more popular library in python.

Note: Run this progran in jupytre notebook for better visualization.

program.............

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

We define the logistic function by:

fr(x)=rx(1−x)

def logistic(r, x):
    return r * x * (1 - x)

//for graph

x = np.linspace(0, 1)
fig, ax = plt.subplots(1, 1)
ax.plot(x, logistic(2, x), 'k')

x(r)n+1=fr(x(r)n)=rx(r)n(1−x(r)n)

def plot_system(r, x0, n, ax=None):
    # Plot the function and the
    # y=x diagonal line.
    t = np.linspace(0, 1)
    ax.plot(t, logistic(r, t), 'k', lw=2)
    ax.plot([0, 1], [0, 1], 'k', lw=2)

    # Recursively apply y=f(x) and plot two lines:
    # (x, x) -> (x, y)
    # (x, y) -> (y, y)
    x = x0
    for i in range(n):
        y = logistic(r, x)
        # Plot the two lines.
        ax.plot([x, x], [x, y], 'k', lw=1)
        ax.plot([x, y], [y, y], 'k', lw=1)
        # Plot the positions with increasing
        # opacity.
        ax.plot([x], [y], 'ok', ms=10,
                alpha=(i + 1) / n)
        x = y

    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)
    ax.set_title(f"$r={r:.1f}, \, x_0={x0:.1f}$")


fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6),
                               sharey=True)
plot_system(2.5, .1, 10, ax=ax1)
plot_system(3.5, .1, 10, ax=ax2)

for 10000 iteration.

n = 10000
r = np.linspace(2.5, 4.0, n)
iterations = 1000
last = 100
x = 1e-5 * np.ones(n)

he Lyapunov exponent is defined by

λ(r)=limn→∞1n∑i=0n−1log∣∣∣dfrdx(x(r)i)∣∣∣

lyapunov = np.zeros(n)
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 9),
                               sharex=True)
for i in range(iterations):
    x = logistic(r, x)
    # We compute the partial sum of the
    # Lyapunov exponent.
    lyapunov += np.log(abs(r - 2 * r * x))
    # We display the bifurcation diagram.
    if i >= (iterations - last):
        ax1.plot(r, x, ',k', alpha=.25)
ax1.set_xlim(2.5, 4)
ax1.set_title("Bifurcation diagram")

# We display the Lyapunov exponent.
# Horizontal line.
ax2.axhline(0, color='k', lw=.5, alpha=.5)
# Negative Lyapunov exponent.
ax2.plot(r[lyapunov < 0],
         lyapunov[lyapunov < 0] / iterations,
         '.k', alpha=.5, ms=.5)
# Positive Lyapunov exponent.
ax2.plot(r[lyapunov >= 0],
         lyapunov[lyapunov >= 0] / iterations,
         '.r', alpha=.5, ms=.5)
ax2.set_xlim(2.5, 4)
ax2.set_ylim(-2, 1)
ax2.set_title("Lyapunov exponent")
plt.tight_layout()

Lyapunov exponent  is positive when the system is chaotic


Related Solutions

gray code to excess 3 code converter circuit and its logic diagram and ic based diagram
gray code to excess 3 code converter circuit and its logic diagram and ic based diagram
!!TRANSLATE TO MATLAB CODE!! INPUT: Function f, endpoint values a, b, tolerance TOL, maximum iterations NMAX...
!!TRANSLATE TO MATLAB CODE!! INPUT: Function f, endpoint values a, b, tolerance TOL, maximum iterations NMAX CONDITIONS: a < b, either f(a) < 0 and f(b) > 0 or f(a) > 0 and f(b) < 0 OUTPUT: value which differs from a root of f(x) = 0 by less than TOL N ← 1 while N ≤ NMAX do // limit iterations to prevent infinite loop c ← (a + b)/2 // new midpoint if f(c) = 0 or (b...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
Locate the bifurcation values for the one-parameter family and draw the phase lines for values of...
Locate the bifurcation values for the one-parameter family and draw the phase lines for values of the parameter slightly smaller than, slightly larger than, and at the bifurcation values. Explain steps. 1.) dy/dt = y^2 + a
c++ I need a code that will fill an array size of 1000, an array of...
c++ I need a code that will fill an array size of 1000, an array of size 2000, and an array size of 10000, with random int values. Basically like this: array1[1000] = filled all with random numbers array2[2000] = filled all with random numbers array3[10000] = filled all with random numbers C++ no need for print
how regulatory differences between the US and EU have led to a bifurcation in some world...
how regulatory differences between the US and EU have led to a bifurcation in some world agricultural markets. In the course of your response provide background information on the definition and development of GMOs
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
1 Draw a stack diagram to show how the following code is executed and write the...
1 Draw a stack diagram to show how the following code is executed and write the generated output. def sequence(a, b, c): if a < b < c: return a + b + c if a >= b: return sequence(a - 1, b, c) if a >= c: return sequence(c, b, a) if b >= c: return sequence(c, b, a + 2) return 0 print(sequence(10, 10, 10)) 2 Draw a stack diagram to show how the following code is executed...
Provide explanation about Iterations. Give examples and write a program.
Provide explanation about Iterations. Give examples and write a program.
def sequentialSearch(theList, item):     #**** to be changed:     # counts the iterations of the while...
def sequentialSearch(theList, item):     #**** to be changed:     # counts the iterations of the while loop and returns this value     found = False     index = 0     while index < len(theList) and not found:         if theList[index] == item:             found = True         index = index + 1       return found                   def binarySearch(theList, item):     #**** to be changed:     # counts the iterations of the while loop and returns this value     startIndex = 0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT