importrandomimportmathdefestimer_surface(nombre_points):# Compteur de succès
succes=0# Générer des points aléatoires et vérifier s'ils sont à l'intérieur du cœur
for_inrange(nombre_points):x=-2+4*random.random()y=-3+4*random.random()# Partie supérieure du cœur
ify>=0and((x-1)**2+y**2<=1or(x+1)**2+y**2<=1):succes+=1# Partie inférieure du cœur
elify<=0and((x>=0andy>=1.5*x-3)or(x<=0andy>=-1.5*x-3)):succes+=1# Calculer la surface estimée
surface_estimee=(succes/nombre_points)*8*8returnsurface_estimee,succesdefintervalle_confiance(surface_estimee,succes,nombre_points,z=1.96):# Calculer la proportion
p=succes/nombre_points# Calculer l'erreur standard
erreur_standard=math.sqrt(p*(1-p)/nombre_points)# Calculer l'intervalle de confiance
borne_inferieure=surface_estimee-z*erreur_standard*8*8borne_superieure=surface_estimee+z*erreur_standard*8*8returnborne_inferieure,borne_superieure# Nombre de points à générer
nombre_points=100000# Estimer la surface
surface_estimee,succes=estimer_surface(nombre_points)# Calculer l'intervalle de confiance
borne_inferieure,borne_superieure=intervalle_confiance(surface_estimee,succes,nombre_points)# Arrondir les valeurs à deux décimales
surface_estimee_arrondie=round(surface_estimee,2)borne_inferieure_arrondie=round(borne_inferieure,2)borne_superieure_arrondie=round(borne_superieure,2)# Afficher les résultats
print("Estimation surface : "+str(surface_estimee_arrondie))print("Intervalle de confiance (95%)\n["+str(borne_inferieure_arrondie)+", "+str(borne_superieure_arrondie)+"]")
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
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.