版本比较
【理论与解析】浅谈概率论
正文
增加 3 行删除 94 行
123456758 行未改动66676869707172737415 行未改动909192939495969798151 行未改动全部展开25025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734814 行未改动## 前言::::warning[警告]本文字符数达到了惊人的 $10390$ 字符,请谨慎点开!::::### 参与编写成员**主编:**[**Furina_oier**](https://www.luogu.com.cn/user/1399773) ;58 行未改动$$P(A)=\frac{事件 A 包含的样本点个数}{样本空间总样本点个数}=\frac{n(A)}{n(\Omega)}$$#### 例题掷一颗均匀骰子,求出现偶数点的概率。##### 解法#1共有 $6$ 种等可能的结果,出现偶数点有 $3$ 种,$\therefore P(出现偶数点)=\frac{3}{6}=\frac{1}{2}$##### 解法#2设,出现偶数点这一事件为事件 $A$ 。15 行未改动则称 $P(A)$ 为事件 $A$ 的概率。### 概率的核心性质1. $P(\varnothing)=0$2. 有限可加性:$A_1,A_2\cdots A_n$ 互斥,则 $P(\bigcup^n_{i=1}A_i)=\sum^n_{i=1}P(A_i)$3. 对立事件公式:$P(\overline A)=1-P(A)$4. 减法公式:$P(A-B)=P(A)-P(AB)$5. **加法公式**:$P(A\cup B)=P(A)+P(B)-P(AB)$151 行未改动全部展开$$\frac{1}{n}\sum_{i=1}^n X_i \xrightarrow{P} \mu$$### 独立同分布中心极限定理$X_1,\dots,X_n$独立同分布,$E(X_i)=\mu,D(X_i)=\sigma^2$,则:$$\lim_{n\to\infty}P\left\{\frac{\sum_{i=1}^n X_i - n\mu}{\sqrt{n}\sigma} \le x\right\} = \Phi(x)$$## 第十一章 概率代码实现本章由 [**Furina_oier**](https://www.luogu.com.cn/user/1399773) 与 [**LMH_Diana**](https://www.luogu.com.cn/user/1419950) 共同编写。::::success[代码]```cpp#include<bits/stdc++.h>#define int long longusing namespace std;const int N=1e5+5;int inline read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=getchar();return x*f;}void write(int x,int typ){if(x<0)putchar('-'),x=-x;if(x<10)putchar(x+'0');else write(x/10,0),putchar(x%10+'0');if(typ==0) return;else if(typ==1) putchar(' ');else putchar('\n');}double uniform_rand(){static random_device rd;static mt19937 gen(rd());uniform_real_distribution<> dis(0.0,1.0);return dis(gen);}double binomial_prob(int n,double p,int k){if(k<0||k>n) return 0.0;double c=1.0;for(int i=1;i<=k;i++) c=c*(n-k+i)/i;return c*pow(p,k)*pow(1-p,n-k);}double poisson_prob(double lambda,int k){if(k<0) return 0.0;double res=exp(-lambda);for(int i=1;i<=k;i++) res*=lambda/i;return res;}double normal_cdf(double x){return 0.5*erfc(-x*sqrt(0.5));}void law_of_large_numbers(int n){vector<double> nums(n);for(int i=0;i<n;i++) nums[i]=uniform_rand();double avg=accumulate(nums.begin(),nums.end(),0.0)/n;cout<<"试验次数:"<<n<<",平均值:"<<fixed<<setprecision(6)<<avg<<endl;}void calc_expectation_variance(const vector<double>& x,const vector<double>& p){double E=0,E2=0;for(int i=0;i<x.size();i++){E+=x[i]*p[i];E2+=x[i]*x[i]*p[i];}double D=E2-E*E;cout<<"期望 E(X) = "<<E<<endl;cout<<"方差 D(X) = "<<D<<endl;}inline void solve(){cout<<"===== 概率论 C++ 实现 ====="<<endl;cout<<"\n1. 二项分布 B(n=10,p=0.5), k=6"<<endl;cout<<"P(X=6) = "<<binomial_prob(10,0.5,6)<<endl;cout<<"\n2. 泊松分布 P(λ=3), k=2"<<endl;cout<<"P(X=2) = "<<poisson_prob(3,2)<<endl;cout<<"\n3. 标准正态分布 Φ(1.96) = "<<normal_cdf(1.96)<<endl;cout<<"\n4. 大数定律模拟:"<<endl;law_of_large_numbers(100);law_of_large_numbers(1000);law_of_large_numbers(10000);cout<<"\n5. 0-1分布期望方差计算:"<<endl;vector<double> x={0,1};vector<double> p={0.5,0.5};calc_expectation_variance(x,p);}signed main(){solve();return 0;}```::::## 后续:致谢感谢每一位阅读本文的读者,希望你们能为文章提出宝贵意见;感谢每一位参与编写和审核本文章的 $\texttt{OIER}$ 。14 行未改动123456758 行未改动66676869707172737415 行未改动909192939495969798151 行未改动全部展开25025125225325425525625714 行未改动## 前言::::warning[警告]本文字符数达到了惊人的 $8063$ 字符,请谨慎点开!::::### 参与编写成员**主编:**[**Furina_oier**](https://www.luogu.com.cn/user/1399773) ;58 行未改动$$P(A)=\frac{事件 A 包含的样本点个数}{样本空间总样本点个数}=\frac{n(A)}{n(\Omega)}$$#### 例题掷一颗均匀骰子,求出现偶数点的概率。##### 解法#1共有 $6$ 种等可能的结果,出现偶数点有 $3$ 种,$\therefore P(出现偶数点)=\frac{3}{6}=\frac{1}{2}$##### 解法#2设,出现偶数点这一事件为事件 $A$ 。15 行未改动则称 $P(A)$ 为事件 $A$ 的概率。### 概率的核心性质1. $P(\varnothing)=0$2. 有限可加性:$A_1,A_2\cdots A_n$ 互斥,则 $P(\bigcup^n_{i=1}A_i)=\sum^n_{i=1}P(A_i)$3. 对立事件公式:$P(\overline A)=1-P(A)$4. 减法公式:$P(A-B)=P(A)-P(AB)$5. **加法公式**:$P(A\cup B)=P(A)+P(B)-P(AB)$151 行未改动全部展开$$\frac{1}{n}\sum_{i=1}^n X_i \xrightarrow{P} \mu$$### 独立同分布中心极限定理$X_1,\dots,X_n$独立同分布,$E(X_i)=\mu,D(X_i)=\sigma^2$,则:$$\lim_{n\to\infty}P\left\{\frac{\sum_{i=1}^n X_i - n\mu}{\sqrt{n}\sigma} \le x\right\} = \Phi(x)$$::::## 后续:致谢感谢每一位阅读本文的读者,希望你们能为文章提出宝贵意见;感谢每一位参与编写和审核本文章的 $\texttt{OIER}$ 。14 行未改动