``````

In [1]:

import numpy as np
import sympy as sp
import pandas as pd
import math

import midterm as p1

import matplotlib.pyplot as plt

# Needed only in Jupyter to render properly in-notebook
%matplotlib inline

``````

# Midterm

## Chinmai Raman

### 3/22/2016

\$x_{n+1} = rx_n(1-x_n)\$ for \$x_0\$ in \$[0,1]\$ and \$r\$ in \$[2.9,4]\$

### \$x_0\$ = 0.5, \$r\$ = 2.5

``````

In [2]:

p1.sequence(0.5, 2.5, 100)

``````
``````

This function is defined only where r is a real value in [2.9, 4]. Please supply an r value in the range.

``````

The function is not graphable at r = 2.5

### \$x_0\$ = 0.5, \$r\$ = 3.2

``````

In [13]:

p1.sequence(0.5, 3.2, 10)

``````
``````

Out[13]:

[0.5,
0.8,
0.512,
0.7995392,
0.512884056522752,
0.7994688034800593,
0.5130189943751092,
0.7994576185134749,
0.5130404310855622,
0.7994558309027286,
0.5130438570827405]

``````
``````

In [4]:

p1.graph(0.5, 3.2, 100)

``````
``````

``````

The sequence approaches an oscillation between 0.799 (at odd indices of x) and 0.513 (at even indices of x)

### \$x_0\$ = 0.5, \$r\$ = 3.5

``````

In [12]:

p1.sequence(0.5, 3.5, 10)

``````
``````

Out[12]:

[0.5,
0.875,
0.3828125,
0.826934814453125,
0.5008976948447526,
0.87499717950388,
0.3828199037744718,
0.826940887670016,
0.500883795893397,
0.8749972661668659,
0.38281967628581853]

``````
``````

In [6]:

p1.graph(0.5, 3.5, 100)

``````
``````

``````

The sequence approaches an oscillation between two sets of two numbers: 0.501 (at indices 4n), 0.875 (at indices 4n+1), 0.383 (at indices 4n+2), and 0.827 (at indices 4n+3) where n is a whole number

### Varying initial condition \$x_0\$ in the range \$[0,1]\$ with r = 3.2

``````

In [11]:

p1.sequence(0.25, 3.2, 10)

``````
``````

Out[11]:

[0.25,
0.6000000000000001,
0.768,
0.5701632,
0.7842468011704321,
0.5414520192780059,
0.7945015363128827,
0.522460304349926,
0.7983857111312278,
0.5150910956566768,
0.7992712282620194]

``````
``````

In [8]:

p1.graph(0.25, 3.2, 100)

``````
``````

``````
``````

In [10]:

p1.sequence(0.75, 3.2, 10)

``````
``````

Out[10]:

[0.75,
0.6000000000000001,
0.768,
0.5701632,
0.7842468011704321,
0.5414520192780059,
0.7945015363128827,
0.522460304349926,
0.7983857111312278,
0.5150910956566768,
0.7992712282620194]

``````
``````

In [10]:

p1.graph(0.75, 3.2, 100)

``````
``````

``````

The sequences both converge to the same pair of values (0.513 and 0.799) at the same speed. At a fixed r, the value of \$x_0\$ does not have an impact on the values that the sequence converges to.

### Varying initial condition \$x_0\$ in the range \$[0,1]\$ with r = 3.5

``````

In [9]:

p1.sequence(0.25, 3.5, 10)

``````
``````

Out[9]:

[0.25,
0.65625,
0.78955078125,
0.5815612077713013,
0.8517171928541032,
0.44203255687790355,
0.8632392143826028,
0.41320045597148347,
0.8486304370475457,
0.4495988642741304,
0.8661090393113987]

``````
``````

In [12]:

p1.graph(0.25, 3.5, 100)

``````
``````

``````
``````

In [8]:

p1.sequence(0.75, 3.5, 10)

``````
``````

Out[8]:

[0.75,
0.65625,
0.78955078125,
0.5815612077713013,
0.8517171928541032,
0.44203255687790355,
0.8632392143826028,
0.41320045597148347,
0.8486304370475457,
0.4495988642741304,
0.8661090393113987]

``````
``````

In [14]:

p1.graph(0.75, 3.5, 100)

``````
``````

``````

The sequences both converge to the same 4 values (0.501, 0.875, 0.383, and 0.827) at the same speed. At a fixed r, the value of \$x_0\$ does not have an impact on the values that the sequence converges to.

### \$r\$ = 3.5441

``````

In [7]:

p1.sequence(0.5, 3.5441, 1000000)[-9:-1]

``````
``````

Out[7]:

[0.5228976900798744,
0.8841668134458163,
0.3629720474657136,
0.8194786400888046,
0.5242907577195693,
0.883933836008775,
0.36360626458848544,
0.8200932179200039]

``````
``````

In [51]:

p1.graph(0.5, 3.5441, 100)

``````
``````

``````

The sequence seems to converge to an oscillation between 8 values, approximately: (0.5229, 0.8842, 0.3630, 0.8195, 0.5243, 0.8839, 0.3636, 0.8201). It could be argued that the sequence oscillates between four points, but there is a slight variation in the 3rd or 4th decimal place in the values of the sequence at the indices 4n, 4n+1, 4n+2, 4n+3. There seems to be an variation in every oscillation at index 4n+k (\$0<=k<=3\$ and n is a whole number) between two values.

``````

In [6]:

p1.sequence(0.75, 3.5441, 1000000)[-9:-1]

``````
``````

Out[6]:

[0.8200932179200039,
0.5228976900798744,
0.8841668134458163,
0.3629720474657136,
0.8194786400888046,
0.5242907577195693,
0.883933836008775,
0.36360626458848544]

``````

Varying \$x_0\$ with a constant \$r\$ does not change the values that the sequence converges to and oscillates between for a large N

### \$r\$ = 3.5699

``````

In [5]:

p1.sequence(0.5, 3.5699, 1000000)[-33:-1]

``````
``````

Out[5]:

[0.49636520717822474,
0.8924278354848516,
0.34271180631453335,
0.8041571880915597,
0.5622178567675878,
0.8786556968344851,
0.3806222498332767,
0.8416001864762425,
0.4759009150485851,
0.8904017238296705,
0.34837402504063025,
0.8104014415155337,
0.5485185089306204,
0.884071292223974,
0.36587634676293335,
0.8282555178586006,
0.5078122597020139,
0.8922571239992436,
0.3431900113236088,
0.8046933989384318,
0.5610523833434796,
0.8791685779017997,
0.3792347235100257,
0.8404106787648518,
0.4787970220678066,
0.890870093361328,
0.34706771325606134,
0.8089811637748658,
0.5516589332793732,
0.8829482028309398,
0.3689515709289408,
0.8311666413487633]

``````
``````

In [18]:

p1.graph(0.5, 3.5699, 100)

``````
``````

``````

The sequence seems to converge to an oscillation between 16 values, approximately: (0.5078122597020139, 0.8922571239992436, 0.3431900113236088, 0.8046933989384318, 0.5610523833434796, 0.8791685779017997, 0.3792347235100257, 0.8404106787648518, 0.4787970220678066, 0.890870093361328, 0.34706771325606134, 0.8089811637748658, 0.5516589332793732, 0.8829482028309398, 0.3689515709289408, 0.8311666413487633). It could be argued that the sequence oscillates between eight points, but there is variation in the 2nd decimal place in the values of the sequence at the indices 8n, 8n+1, 8n+2, 8n+3, 8n+4, 8n+5, 8n+6, 8n+7. There seems to be an variation in every oscillation at index 4n+k (\$0<=k<=7\$ and n is a whole number) between four values. These oscillations of oscillations are larger at r = 3.5699 than at r = 3.5441. The periodicity of the oscillations increases as r increases.

``````

In [4]:

p1.sequence(0.75, 3.5699, 1000000)[-9:-1]

``````
``````

Out[4]:

[0.8046933989384318,
0.5610523833434796,
0.8791685779017997,
0.3792347235100257,
0.8404106787648518,
0.4787970220678066,
0.890870093361328,
0.34706771325606134]

``````

Varying \$x_0\$ with a constant \$r\$ does not change the values that the sequence converges to and oscillates between for a large N

### \$r\$ = 3.57

``````

In [10]:

p1.sequence(0.5, 3.57, 1000000)[-33:-1]

``````
``````

Out[10]:

[0.4960958395524152,
0.8924455843863822,
0.3426716739654025,
0.8041346382429303,
0.5622825749004056,
0.878651544683678,
0.3806441375199326,
0.8416424157871522,
0.4758112412543736,
0.8904112071027348,
0.34835734904585025,
0.8104060878894045,
0.5485235763462671,
0.8840943012626876,
0.3658234968229741,
0.8282280976028125,
0.5078907479202178,
0.8922777178672167,
0.34314194567165146,
0.8046621163285997,
0.5611361517008182,
0.8791566643101159,
0.37927759935593724,
0.8404711840783617,
0.4786633609398336,
0.8908747497660097,
0.3470644400834328,
0.8090002508114317,
0.5516322766445462,
0.8829827655903487,
0.3688673985009418,
0.8311111397419982]

``````
``````

In [28]:

p1.graph(0.5, 3.57, 100)

``````
``````

``````

The sequence seems to converge to an oscillation between 16 values, approximately: (0.5078907479202178, 0.8922777178672167, 0.34314194567165146, 0.8046621163285997, 0.5611361517008182, 0.8791566643101159, 0.37927759935593724, 0.8404711840783617, 0.4786633609398336, 0.8908747497660097, 0.3470644400834328, 0.8090002508114317, 0.5516322766445462, 0.8829827655903487, 0.3688673985009418, 0.8311111397419982). It could be argued that the sequence oscillates between thirty-two points, but the values were two fine to compare adequately by eye. There seems to be an variation in every oscillation at index 4n+k (\$0<=k<=7\$ and n is a whole number) between eight values. These oscillations of oscillations are larger at r = 3.57 than at r = 3.5699 and r = 3.5441. Again, the periodicity of the oscillations is greater as r increases.

``````

In [2]:

p1.sequence(0.2, 3.57, 100000)[-8:-1]

``````
``````

Out[2]:

[0.5098314419789786,
0.8921549336125519,
0.34348579371470583,
0.8050467925342573,
0.5602988420814857,
0.8795196572277663,
0.37829444230645615]

``````

Varying \$x_0\$ with a constant \$r\$ does not change the values that the sequence converges to and oscillates between for a large N

### Bifurcation Diagram

``````

In [5]:

p1.asymptote_graph(0.5, 2.9, 4, 0.0001, 200)

``````
``````

``````

### Problem 4

The following are graphs zoomed into specific regions of the graph above:

### Zoom graph 1

``````

In [7]:

p1.zoom_graph(0.5, 2.9, 4, 0.0001, 1000, [3.54, 3.55, 0.78, 0.9])

``````
``````

``````

### Zoom graph 2

``````

In [11]:

p1.zoom_graph(0.5, 2.9, 4, 0.0001, 1000, [3.568, 3.572, 0.33, 0.39])

``````
``````

``````

The original bifurcation diagram in problem 3 shows the repeated bifurcation in \$x_n\$ as r approaches 4 from 2.9 with an \$x_0\$ of 0.5 . This means that the oscillations go from converging to one value to oscillating between two values, four values, eight values, and so on. The Bifurcations occur at and around certain values of r, for example: the one to two bifurcation occurs around r = 3.0 . The second is around 3.54, as illustrated in Zoom graph 1. As r increases, the periodicity of the oscillations increases, as can be seen in Zoom graph 2. The number of values that the discrete update map converges to double with each bifurcation, as r increases. I would not have guessed this complicated a behavior from the simple equation above. I would plot \$f(x)=rx_n(1-x_n)\$ and \$x_{n+1}=x_n\$ with \$x_n\$ and \$x_{n+1}\$ the recommend using cobwebbing (recursive graphical method). I would like to explore further the behavior of this update map at values of r below 2.9 and above 4.

``````

In [ ]:

``````