Cumulative Normal Distribution Function in C/C++

后端 未结 7 2205
走了就别回头了
走了就别回头了 2020-12-07 14:15

I was wondering if there were statistics functions built into math libraries that are part of the standard C++ libraries like cmath. If not, can you guys recommend a good st

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 14:34

    From https://en.cppreference.com/w/cpp/numeric/math/erfc

    Normal CDF can be calculated as below:

    #include 
    #include 
    #include 
    using namespace std;
    
    double normalCDF(double x) // Phi(-∞, x) aka N(x)
    {
        return erfc(-x / sqrt(2))/2;
    }
    

    Using 2.0 instead of 2 in the denominator helps in getting decimals instead of integers.

    Hope that helps.

提交回复
热议问题