# -*- coding: utf-8 -*- """ Created on Thu Feb 05 17:44:21 2015 Exercice 15-1: Simulation d'une réaction en chaine @author: grivet """ import numpy as np import matplotlib.pyplot as plt N = 1000; NR = 100 P1 = 0.1; P2 = 0.05 tab = np.zeros(N); n0 = np.zeros(NR); n1 = np.zeros(NR) n2 = np.zeros(NR) for ir in range(NR): for i in range(N): x = np.random.random() if x <= P1 and tab[i] == 0: tab[i] = 1 x = np.random.random() if x <= P2 and tab[i] == 1: tab[i] = 2 for i in range(N): if tab[i] == 0: n0[ir] += 1 elif tab[i] == 1: n1[ir] += 1 elif tab[i] == 2: n2[ir] += 1 else: break plt.plot(n0,'ok',n1,'ob',n2,'or') #fig = plt.gca() plt.title = 'Populations dans une réaction en chaine' plt.xlabel("temps simulé") plt.ylabel("populations")