Search code examples
phpnormal-distributionintegral

Best method of calculating the integral of a function in PHP?


I am making a normal distribution calculator in PHP, but I can't figure out how to calculate the integral of a function using PHP. I've searched the web and stackoverflow, but I can't find anything on the topic. The closest I've come is via php.net where someone referrers to the Composite Simpson's Rule to get an approximation, but I would like to get a precise result and not just an approximation.

Is there any commonly know way to achieve my goal, that I am missing, and if there are several which would be the best for calculating normal distribution?


Solution

  • The integral of the normal distribution is known as the error function (often abbreviated as erf). There doesn't appear to be any native implementation in PHP, but the Wikipedia page has several good approximations under "Approximation with elementary functions".