limite_centrale.py

Created by gianfranco-oddenino

Created on November 24, 2022

997 Bytes

Teorema del limite centrale: la somma di n variabili indipendenti aventi identica distribuzione è una variabile che si distribuisce normalmente qualsiasi sia la tipologia di distribuzione iniziale.


# Teorema del limite centrale:
# la somma di n variabili indipendenti aventi identica distribuzione è una variabile
# che si distribuisce normalmente qualsiasi sia la tipologia di distribuzione iniziale

from random import *
from matplotlib.pyplot import *

print("Verifica empirica del teorema del limite centrale")
print("sommando n variabili casuali con distribuzione uniforme")

# richiede il numero di variabili casuali da sommare
n = int(input("Valore di n? (max 10) "))

# richiede il numero di estrazioni da affettuare
estrazioni = int(input("N. di estrazioni? "))

x = [i for i in range(n*9+1)]   # riempie la lista con i numeri da 0 a n*9
f = (n*9+1)*[0]                 # riempie la lista con n*9+1 numeri 0 (freq. iniziali)

for i in range(estrazioni):
  # somma n variabili casuali con distribuzione uniforme
  valore = 0
  for j in range(n):
    valore += randint(0,9)
  # incrementa di 1 la frequenza del valore ottenuto
  f[valore] += 1
    
bar(x,f)
show()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.