![]() |
A program for Normal Distribution on the 42s - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: A program for Normal Distribution on the 42s (/thread-196607.html) |
A program for Normal Distribution on the 42s - snaggs - 09-19-2011 I couldn't find one on the net, so I converted the one on my 35s for the 42s. It's my first 42s program. SET = Set mean and std dev. 00 { 372-Byte Prgm } Re: A program for Normal Distribution on the 42s - Ángel Martin - 09-21-2011 Very interesting. You could add this as an article in the museum so it doesn't get lost in the heaps of forum archives.
No I remember why the 42 is great and also how painful typing all these lines can be!
Re: A program for Normal Distribution on the 42s - Dieter - 09-21-2011 Honestly, I would suggest a different approach, i.e. rational approximations. Expecially for the quantiles. A mid-precision (3;4) type is able to return a result with absolute error less than 5 E-6 within one second (!) on the 35s. The 42s should be able to do the same.
Would you try the following examples with your program and see how long it takes? p = 0,1 => z = 1,28155Dieter Re: A program for Normal Distribution on the 42s - snaggs - 09-21-2011 Will do, but it is quite slow, 10's of seonds. Can you link me to some theory or an algorithm on rational approximations? Faster would be. Better! Also, the programmable menus is a big bonus of the 42s in comparison to the 35s.
Daniel.
Re: A program for Normal Distribution on the 42s - Paul Dale - 09-21-2011 Dieter and I had a long long discussion about ways to implement the quantile (& other statistical) functions. I archived many of the tidbits as part of the documentation for the 34S.
- Pauli
Re: A program for Normal Distribution on the 42s - Dieter - 09-22-2011 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.
LBL Z 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.
Dieter
|