开发者

How can I implement NORMDIST function in objective c?

I am trying to implement a NORMDIST feature in my iphone application, but I am not sure what library to import, or how I would go about doing this.

If someone can point me in a direction, that wou开发者_如何学Gold be awesome.


Not sure if this is precisely what you're looking for but here is an algorithm for calculating a cumulative normal distribution approximation. There is an implementation in C++ that should be fairly trivial to port to Obj-C.


Try this:

static double normdist (double x, double mean, double standard_dev) {
double res;
x = (x - mean) / standard_dev;

if (x == 0) {
    res = 0.5;
} else {
    double oor2pi = 1 / (sqrt(2.00000  * 3.14159265358979323846));
    double t = 1 / (1.0000000 + 0.2316419 * fabs(x));
    t *= oor2pi * exp(-0.5 * x * x)
         * (0.31938153 + t
            * (-0.356563782 + t
               * (1.781477937 + t
                  * (-1.821255978 + t * 1.330274429))));

    if (x >= 0)
        res = 1.00000 - t;
    else
        res = t;
}
return res;

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜