画出标准正态分布的曲线图 plot 命令正态分布的公式定义如下: 10’ f(x) = 1 √ 2πσ e − (x 2 − σ µ 2 ) 2 (µ ∈ R, σ > 0)]
时间: 2024-05-19 21:16:15 浏览: 10
由于标准正态分布的公式中,$\mu=0$,$\sigma=1$,因此可以简化为:
$$f(x)=\frac{1}{\sqrt{2\pi}}e^{-\frac{x^2}{2}}$$
使用Python的Matplotlib库可以画出标准正态分布的曲线图:
```python
import numpy as np
import matplotlib.pyplot as plt
# 定义标准正态分布的概率密度函数
def normal_pdf(x):
return np.exp(-x**2/2)/np.sqrt(2*np.pi)
# 生成一组随机数据
x = np.linspace(-4, 4, 1000)
y = normal_pdf(x)
# 绘制标准正态分布的曲线图
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('Probability density')
plt.title('Standard normal distribution')
plt.show()
```
运行上述代码可以得到标准正态分布的曲线图:
![Standard normal distribution](https://i.imgur.com/9tPHrEe.png)
相关问题
画出标准正态分布的曲线图 plot 命令正态分布的公式定义如下: 10’ f(x) = 1 √ 2πσ e − (x 2 − σ µ 2 ) 2 (µ ∈ R, σ > 0)
由于标准正态分布的公式是 f(x) = 1/√(2π) e^(-x^2/2),因此我们需要将其转化为题目给定的形式。
设 x = σz + µ,则有:
f(x) = 1/√(2πσ^2) e^(-(x-µ)^2/(2σ^2))
= 1/√(2π) e^(-(σz)^2/(2σ^2)) (因为 (x-µ)/σ = z)
= 1/√(2π) e^(-z^2/2)
可以看出,将标准正态分布的概率密度函数 f(z) = 1/√(2π) e^(-z^2/2) 中的 z 替换为 (x-µ)/σ,即可得到一般形式的概率密度函数。
因此,标准正态分布的曲线图如下所示:
```python
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 1000)
y = 1 / np.sqrt(2 * np.pi) * np.exp(-x ** 2 / 2)
plt.plot(x, y)
plt.title("Standard Normal Distribution")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.show()
```
![Standard_Normal_Distribution](https://i.imgur.com/6zK2v1N.png)
使用x = np.random.normal(0, 1, 1000)画出正态分布
以下是使用Matplotlib和NumPy库来绘制正态分布图的代码:
```python
import numpy as np
import matplotlib.pyplot as plt
# 生成1000个随机数符合正态分布
x = np.random.normal(0, 1, 1000)
# 绘制直方图
plt.hist(x, bins=30, density=True, alpha=0.6, color='g')
# 绘制正态分布曲线
mu, sigma = 0, 1
y = ((1 / (np.sqrt(2 * np.pi) * sigma)) *
np.exp(-0.5 * (1 / sigma * (np.arange(-5, 5, 0.1) - mu))**2))
plt.plot(np.arange(-5, 5, 0.1), y, '--')
# 添加标签和标题
plt.xlabel('x')
plt.ylabel('Frequency')
plt.title('Normal distribution')
# 显示图形
plt.show()
```
这将生成一个包含直方图和正态分布曲线的图形。