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

l=1
def position(N):
    poslist=[0]
    for i in range(N):
        poslist.append(poslist[i]+random.choice([+l,-l]))
    return np.array(poslist)

N=10
temps=[j for j in range(N+1)]
plt.plot(temps,position(N))
plt.title('courbe 1')
plt.xlabel('t(s)')
plt.ylabel('x')
plt.grid()
plt.show()  

N=100
temps=[j for j in range(N+1)]
plt.plot(temps,position(N))
plt.title('courbe 2')
plt.xlabel('t(s)')
plt.ylabel('x')
plt.grid()
plt.show() 

N=1000
temps=[j for j in range(N+1)]
for i in range(0,4):
    plt.plot(temps,position(N))
    plt.title('courbe 3')
plt.xlabel('t(s)')
plt.ylabel('x')
plt.grid()
plt.show()  

Np=1000
T=np.zeros((N+1,Np))
for i in range(Np):
    T[:,i]=position(N)
    
def f(l): 
    s=0
    for i in range(len(l)):
        s=s+l[i]**2
    return s/len(l)

def g(l): 
    s=0
    for i in range(len(l)):
        s=s+l[i]
    return s/len(l)

l1=[]
for i in range(N+1):
    l1.append(f(T[i,:])) 
plt.plot(temps,l1) 
plt.xlabel('t(s)')
plt.title('courbe 4')
plt.grid()
plt.show()

l2=[]
for i in range(N+1):
    l2.append(g(T[i,:]))
plt.plot(temps,l2) 
plt.xlabel('t(s)')
plt.title('courbe 5')
plt.grid()
plt.show()




