import math
from scipy.special import comb, perm
def prop(p,n,m):
return comb(m,n)*p**n*(1-p)**(m-n)
def occur3prob(p,m):
return 1-prop(p,0,m)-prop(p,1,m)-prop(p,2,m)
occur3prob(0.15, 100)
0.9999848840805048
def search(target,m):
if 0<target<1:
pass
else:
return None
l=0.0
r=1.0
while True:
mid=(l+r)*0.5
l_r=occur3prob(l,m)
r_r=occur3prob(r,m)
mid_r=occur3prob(mid,m)
#print(l,r,l_r,r_r)
l_d=target-l_r
r_d=target-r_r
mid_d=target-mid_r
if abs(l_d)<=0.1**10:
return l
elif abs(r_d)<=0.1**10:
return r
if l_d*mid_d<0:
r=mid
elif mid_d*r_d<0:
l=mid
search(0.99, 100)
0.08141194633208215
occur3prob(0.08, 100)
0.9887271969313339
def occuriprob(p,m,times):
sum_prob=0.0
for i in range(times):
sum_prob+=prop(p,i,m)
return 1-sum_prob
occuriprob(0.08,100,10),1.0/occuriprob(0.08,100,10)
(0.27802201915512237, 3.5968374125146183)
结论:假如共有100个机器,每次运行都有3个机器损坏,那么每个机器损坏的概率约为0.08,可推导出至少有10个机器损坏的概率为0.278,即运行4次有1次损坏机器10个及以上。因此要做好机器损坏10个及以上的应急准备,配足维修人员。