连续型随机变量 (Continuous Random Variables)
如果对于随机变量 的 累积分布函数 (Cumulative Distribution Function, CDF) ,存在非负可积函数 ,使得对于任意实数 ,有: 则称 为 连续型随机变量,称 为 的 概率密度函数 (Probability Density Function, PDF)。
1. 核心性质
- 对几乎所有的 成立。
- 。
- 对任意实数 ,。
2. 常见连续分布
- 均匀分布 (Uniform Distribution): , ()。
- 指数分布 (Exponential Distribution): , ()。
- 正态分布 (Normal Distribution): ,。
- Gamma 分布: 是指数分布的推广
- Beta 分布: ,定义在 上的灵活分布
3. 数字特征 (Numerical Characteristics)
数学期望 (Expectation)
方差 (Variance)
4. 经典例题
:::info 例题 1 设随机变量 ,证明 。 :::
查看解析
令 ,则 ,: 由于被积函数 是奇函数,其积分为 ;第二个积分为标准的正态分布积分,结果为 :
:::info 例题 2 若 ,求其中位数。 :::
查看解析
设中位数为 ,满足 。 指数分布的 CDF 为 ()。
5. 正态分布的重要性质
中心极限定理的预兆:独立随机变量之和的分布在一定条件下收敛于正态分布,这解释了正态分布在自然界中的普遍性。
6. 计算验证:C++ 正态分布模拟
以下代码通过 Box-Muller 变换生成正态分布随机数,并验证其统计特性。
点击查看 C++ 验证代码
#include <iostream>
#include <math>
#include <random>
#include <vector>
#include <iomanip>
using namespace std;
// Box-Muller 变换生成标准正态分布
pair<double, double> box_muller(double u1, double u2) {
double r = sqrt(-2.0 * log(u1));
double theta = 2.0 * M_PI * u2;
return {r * cos(theta), r * sin(theta)};
}
int main() {
random_device rd;
mt19937 gen(rd());
uniform_real_distribution<double> uniform(0.0, 1.0);
const int N = 1000000;
vector<double> samples;
// 生成正态分布样本
for (int i = 0; i < N / 2; ++i) {
double u1 = uniform(gen);
double u2 = uniform(gen);
// 避免 u1 = 0
while (u1 == 0) u1 = uniform(gen);
auto [z1, z2] = box_muller(u1, u2);
samples.push_back(z1);
samples.push_back(z2);
}
// 计算统计量
double sum = 0, sum_sq = 0;
for (double x : samples) {
sum += x;
sum_sq += x * x;
}
double mean = sum / N;
double variance = sum_sq / N - mean * mean;
// 计算各区间频率
int within_1 = 0, within_2 = 0, within_3 = 0;
for (double x : samples) {
if (abs(x) <= 1.0) within_1++;
if (abs(x) <= 2.0) within_2++;
if (abs(x) <= 3.0) within_3++;
}
cout << fixed << setprecision(4);
cout << "样本数量: " << N << endl;
cout << "样本均值: " << mean << " (理论值: 0)" << endl;
cout << "样本方差: " << variance << " (理论值: 1)" << endl;
cout << "\n68-95-99.7 法则验证:" << endl;
cout << "P(|Z| <= 1): " << (double)within_1 / N * 100 << "% (理论: 68.27%)" << endl;
cout << "P(|Z| <= 2): " << (double)within_2 / N * 100 << "% (理论: 95.45%)" << endl;
cout << "P(|Z| <= 3): " << (double)within_3 / N * 100 << "% (理论: 99.73%)" << endl;
return 0;
}
本章节由 SolKnow 系统根据标准教材重写。