|Re: A program for Normal Distribution on the 42s|
Message #6 Posted by Dieter on 22 Sept 2011, 2:19 p.m.,
in response to message #4 by snaggs
As Pauli already pointed out, some of the information that went into the 34s for the statistical distributions is documented, both here in the forum and in the text files that come with the software package.
However, for everyday use on the 35s I designed a simple (3;4) rational approximation with a a maximum absolute error of approx. 5 E-6 so that it will return five valid decimals (+/- 1 ULP). It was designed for p down to 1E-500, i.e. the full working range of the 35s, 42s and others. With a different set of coefficients even higher precision over a smaller range may be achieved. I currently use the following program (slightly modified, that is) to evaluate the quantile: input p, output z.
x<>y ; r := min(p, 1-p)
STO T ; t := sqrt(-2 ln r)
0,010285 ; user Horner's method
RCL*T ; for polynomial in t
+ ; nominator of rat. approx.
+ ; denominator of rat. approx.
0,5 ; set negative sign for p > 0,5)
RCL-P ; (or the other way round, if you prefer)
RND ; make sure that only valid digits are returned ;-)
The normal cdf itself can easily be calculated with the well-known series expansion for smaller z and a continued fraction approach for larger z. On a 12-digit calculator the result in most cases is correct to 11 digits, often even 12. On my 35s the algorithm usually takes between 1 and 4 seconds. IF you don't need that level of precision, there are polynomial and rational approximations for this case as well.
The result of the cdf routine can be used to improve the quantile so that with one single iteration usually 10-12 correct digits are returned. Instead of good old Newton's method I'm using one step of a Hastings iteration for this, so that finally the near-full-precision quantile is returned in 5 seconds or less. The details of this approach have been discussed here as well.
So there are three normal distribution routines on my 35s: One that returns the (almost) exact cdf, a second that returns a more-than-adaequate five-digit approximation for the quantile, and finally a third one that turns this mid-precision result into one with (almost) full precision. The latter two can be combined to return the (almost) exact quantile in 5 seconds or less.