如何按抛物线分布生成数值?离子发射角度采样求助
按抛物线型离子发射角度分布生成随机数值的方法
首先明确你的分布函数:离子发射角度$\theta$的概率密度函数(PDF)为$f(\theta) = 3\cos\theta\sin^2\theta$,其中$\theta \in [0, \pi/2]$,你提到的$\theta_0$是该分布的特征峰值角度(计算可得$\theta_0=\arctan(\sqrt{2})\approx54.7^\circ$)。
用逆变换法的正确实现步骤如下:
推导累积分布函数(CDF)
对归一化后的PDF从$0$到$\theta$积分,得到CDF:
$$F(\theta) = \int_0^\theta 3\cos t \sin^2 t dt$$
通过换元$u=\sin t$($du=\cos t dt$),积分可简化为:
$$F(\theta) = 3\int_0^{\sin\theta} u^2 du = \sin^3\theta$$逆变换生成随机数
取$[0,1]$区间内的均匀分布随机数$U$,令$U=F(\theta)$,解出$\theta$:
$$\theta = \arcsin(U^{1/3})$$代码实现示例(Python)
import numpy as np import matplotlib.pyplot as plt def generate_parabola_angles(n_samples): u = np.random.uniform(0, 1, n_samples) theta = np.arcsin(u ** (1/3)) return theta # 生成样本并验证分布匹配度 samples = generate_parabola_angles(10000) theta_bins = np.linspace(0, np.pi/2, 50) pdf_theory = 3 * np.cos(theta_bins) * (np.sin(theta_bins))**2 plt.hist(samples, bins=theta_bins, density=True, label='采样分布') plt.plot(theta_bins, pdf_theory, 'r-', label='理论分布') plt.xlabel('发射角度θ(弧度)') plt.ylabel('概率密度') plt.legend() plt.show()
你之前用逆变换法失败,大概率是未对原始发射强度函数做归一化处理,或是CDF的推导计算出错——直接用未归一化的$I(\theta)$计算CDF,会导致逆变换后的结果不符合期望分布。
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

