概率论与随机过程--作业2

发布于:2024-12-30 ⋅ 阅读:(50) ⋅ 点赞:(0)
一、选择题

、计算题

1. 食品店有三种蛋糕出售,价格为1元、1.2元、1.5 元,售出概率分别为0.3、0.2、0.5.某天该食品店出售了300 只蛋糕.试用中心极限定理计算,这天的收入至少为395元的概率。

2. 以下数据是某一周50个销售人员获得订单金额(单位:1000元)

6.0  5.9  3.5  2.9  8.7  7.9  7.1  5.0  5.2  3.9

3.7  6.1  5.8  4.1  5.8  6.4  3.8  4.9  5.7  5.5

6.9  4.0  4.8  5.1  4.3  5.4  6.8  5.9  6.9  5.4

2.4  4.9  7.2  4.2  6.2  5.8  3.8  6.2  5.7  6.8

3.4  5.0  5.2  5.3  3.0  3.6  3.8  5.8  4.9  3.7

(1)整理数据制作一个相对频率直方图(分布表,分为7组)

(2)画出箱须图

(3)画出正态概率密度图

import math
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
z = [6.0, 5.9, 3.5 , 2.9 , 8.7 , 7.9 , 7.1 , 5.0 , 5.2 , 3.9,
    3.7,  6.1,  5.8,  4.1,  5.8,  6.4,  3.8,  4.9,  5.7,  5.5,
    6.9,  4.0 , 4.8,  5.1,  4.3,  5.4,  6.8 , 5.9,  6.9,  5.4,
    2.4,  4.9,  7.2,  4.2 , 6.2 , 5.8 , 3.8 , 6.2 , 5.7 , 6.8,
    3.4 , 5.0 , 5.2,  5.3 , 3.0,  3.6,  3.8,  5.8,  4.9,  3.7]
low = min(z)
high = max(z)
bins = [ i for i in range(math.floor(low),math.ceil(high)+1)]
plt.hist(z,bins,weights=np.zeros_like(z)+1./len(z))
plt.legend()
plt.title(u'频率直方图')
plt.show()

plt.boxplot(z)
plt.title(u'销售金额箱须图')
plt.show()

z = np.array(z)
u = z.mean()
var = z.var()
sigma = math.sqrt(var)
xx = np.linspace(u-3*sigma,u+3*sigma,num=100)
yy = [np.exp(-(x-u)**2/(2*sigma**2))/(sigma*math.sqrt(2*math.pi)) for x in xx]
plt.plot(xx,yy)
plt.title(u'正态概率分布图')
plt.show()

程序输出如下:


网站公告

今日签到

点亮在社区的每一天
去签到

热门文章