C++ 正态分布、概率累积密度函数的使用(boost库)

本文介绍在C++中如何使用std::normal_distribution及boost库实现正态分布函数,包括期望、方差的设置,概率密度和正态分布函数值的计算。同时,提供了手动实现标准正态分布概率累积函数的方法。

在C++11以上中在# include <random> 头文件中包含了std::normal_distribution<>b;正态分布函数。

当然也可以下载boost库,里面已经有包装好的正态分布函数。

1.boost库可以在https://www.boost.org/中进行下载最新版的

2.boost库导入C++工程的方法可以参照博客https://blog.youkuaiyun.com/loongsking/article/details/80136004

3.导入好了boost库后示例代码如下

#include <boost\math\distributions\normal.hpp>
#include <iostream>
#include <random>
#include <math.h>
int main() {
	//std::normal_distribution<>b;
	
	boost::math::normal_distribution<> norm(0, 1);//期望,方差
	double PI = acos(-1);
	std::cout<<boost::math::cdf(norm,0)<<std::endl; //0.5  概率密度值,小于0的概率
	std::cout << boost::math::pdf(norm, 0) - 1 / (sqrt(2 * PI)) << std::endl; //0   正态分布函数值
	std::cout << boost::math::cdf(boost::math::complement(norm,1)) << std::en
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值