# sequence convergence - python

Let $$\{p_i : i \in \mathbb{Z}\}$$ be an i.i.d sequence with $$p_i \in (0, 1)$$. Fix this random environment, then consider the random walk $$P[ X_{n+1} = i + 1 | X_n = i] = 1 − P[ X_{n+1} = i − 1 | X_n = i] = p_i.$$

(a) Let $$p_i$$ be $$\frac13$$ or $$\frac23$$, with probability $$\frac12$$ each. Find a deterministic sequence $$a_n$$ such that $$\frac{X_n}{a_n}$$ seems to be converging in distribution to a non-degenerate variable.

(b) Find a distribution with $$\mathbb{E}[p_i] = \frac12$$ such that $$X_n$$ is transient.

(c) In both cases, draw pictures of the space-time trajectorie

I need to simulate the above,I have started working on (a) but I don't get how to find such a sequence. here is my code for the random walk:

import random
import numpy as np
import matplotlib.pyplot as plt

prob = [0.333333333333333333,0.666666666666666666]

start = 0
positions = [start]

rr = np.random.random(1000)
downp = rr < prob[0]
upp = rr > prob[1]

for idownp, iupp in zip(downp, upp):
down = idownp and positions[-1] > -100
up = iupp and positions[-1] < 100
positions.append(positions[-1] - down + up)

plt.plot(positions)
plt.show()


how can I proceed??

• I'm voting to close this question as off-topic because it belongs to cross validated site stats.stackexchange.com – Tasos Apr 26 '19 at 10:13