<>均匀分布U(a,b)均值和方差

·

<>验证U(a,b)的均值是(a+b)/2
""" 2020/2/23 验证U(a,b)的均值是不是(a+b)/2 """ from random import uniform n = int(
input('please enter the number of test: ')) # 试验的次数(越多越趋于真实值) a = float(input(
'please enter the lower bond:: ')) b = float(input('please enter the upper
bond:: ')) sums = 0 for i in range(n): sums += uniform(a,b) print('均值是'+str(
'%.2f'%(sums/n))) print('(a+b)/2的值是:%.2f'%((a+b)/2))
得出均匀分布随机取值所得的数的均值趋近于(a+b)/2
please enter the number of test: 10000 please enter the lower bond: 2 please
enter the upper bond: 10 均值是5.99(a+b)/2的值是:6.00
<>验证U(a,b)的方差是(a-b)**2/12

方差计算方法:

""" 2020/2/27 验证U(a,b)的方差是不是(a-b)**2/12 """ from random import uniform n = int(
input('please enter the number of test: ')) a = float(input('please enter the
lower bond: ')) b = float(input('please enter the lower bond: ')) sums = 0 for i
in range(n): sums += (uniform(a,b)-(a+b)/2)**2 print('方差是'+str('%.2f'%(sums/n)))
print('(a-b)**2/12的值是:%.2f'%(((a-b)**2)/12)) please enter the number of test:
10000 please enter the lower bond: 2 please enter the lower bond: 20 方差是27.17(
a-b)**2/12的值是:27.00

技术
©2020 ioDraw All rights reserved
python简单小游戏代码-10分钟用Python编写一个贪吃蛇小游戏,简单干货|单片机的指针怎么学?韦恩图解决数学问题STM32L系列与普通STM32F系列的比较伪造ACK实现TCP数据注入python装饰器的简单理解TCP/IP协议竟然有这么多漏洞?Python基于Django学生教务选课系统设计python生成随机字符串方法-random模块面试简历上的项目经验