Distribución Poisson
Ejercicio 1
Si el 3% de los engranajes producidos por una empresa son defectuosos, determine las probabil- idades de que en una muestra de 80 engranajes sean sean defectuosos...
(a) dos
(b) más de dos
Programas echo en Python
import math
def binomial_probability(n, k, p):
"""
Calculate the probability of getting exactly k successes in n trials with probability of success p.
Parameters:
n (int): Number of trials
k (int): Number of successes
p (float): Probability of success
Returns:
float: Probability of getting exactly k successes
"""
return (math.comb(n, k) * (p * k) * ((1 - p) * (n - k)))
# Total number of gears in the sample
n = 80
# Probability of a gear being defective
p_defective = 0.03
# (a) Probability of exactly two defective gears
k_a = 2
probability_a = binomial_probability(n, k_a, p_defective)
print(f"The probability of having exactly {k_a} defective gears in a sample of {n} gears is: {probability_a}")
# (b) Probability of more than two defective gears
probability_b = sum(binomial_probability(n, k, p_defective) for k in range(3, n+1))
print(f"The probability of having more than two defective gears in a sample of {n} gears is: {probability_b}")
Ejercicio 2
ii. Un departamento de producción dispone de 35 fresadoras similares. El número de averías en cada máquina es de 0,06 por semana. Determine las probabilidades de tener máquinas averiadas, en cualquier semana.
(a) Fallo en una máquina
(b) menos de tres en cualquier semana
Programas echo en Python
Vimport math
def calculate_probability_of_failures(total_machines, failure_rate, num_failures):
"""
Calculate the probability of having a certain number of failures in any given week.
Args:
total_machines (int): Total number of machines in the production department.
failure_rate (float): Number of failures per machine per week.
num_failures (int): Number of failures for which to calculate the probability.
Returns:
float: Probability of having 'num_failures' failures in any given week.
"""
probability = (math.exp(-total_machines * failure_rate) * (total_machines * failure_rate)**num_failures) / math.factorial(num_failures)
return probability
# Total number of machines in the production department
total_machines = 35
# Number of failures per machine per week
failure_rate = 0.06
# Calculate the probability of failure in one machine in any given week
prob_one_failure = calculate_probability_of_failures(total_machines, failure_rate, 1)
print(f"Probability of having a failure in one machine in any week: {prob_one_failure}")
# Calculate the probability of having less than three failures in any given week
prob_less_than_three_failures = sum([calculate_probability_of_failures(total_machines, failure_rate, i) for i in range(3)])
print(f"Probability of having less than three failures in any week: {prob_less_than_three_failures}")
Ejercicio 3
iii. La probabilidad de que una persona tenga un accidente en un cierto período de tiempo es 0.0003. Para población de 7500 personas, dibuja un histograma mostrando las probabilidades de que hasta 6 personas puedan sufrir un accidente durante este período.
Programas echo en Python
import matplotlib.pyplot as plt
import numpy as np
def poisson_pmf(k, lam):
"""Calculates the Poisson probability mass function for a given k and lambda value.
Parameters:
k (int): Number of events
lam (float): Average rate of events occurring
Returns:
float: Probability of k events occurring
"""
return (lam**k) * np.exp(-lam) / np.math.factorial(k)
def plot_poisson_distribution(lam, n):
"""Plots a Poisson distribution for given lambda and number of events.
Parameters:
lam (float): Average rate of events occurring
n (int): Number of events to consider
"""
probabilities = [poisson_pmf(k, lam) for k in range(n + 1)]
plt.bar(range(n + 1), probabilities, color='skyblue')
plt.xlabel('Number of Accidents')
plt.ylabel('Probability')
plt.title('Poisson Distribution for Accidents')
plt.xticks(range(n + 1))
plt.show()
# Parameters
lambda_val = 0.0003 # Average rate of accidents
population = 7500 # Population size
accident_limit = 6 # Maximum number of accidents to consider
# Calculate lambda for the given population
lam = lambda_val * population
# Plot Poisson distribution for accidents
plot_poisson_distribution(lam, accident_limit)
Comentarios
Publicar un comentario