(12C Platinum) Normal Distribution
12-01-2018, 10:59 AM (This post was last modified: 12-01-2018 12:04 PM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: (12C Platinum) Normal Distribution
(12-01-2018 07:53 AM)Gamo Wrote:  Above Example: FIX 9

See below. ;-)

(12-01-2018 07:53 AM)Gamo Wrote:  Remark: Answer is a bit less accurate due to the Pi precisions

Yes, but why don't you simply use the exact value? Gamo, you are wasting no less than 11 steps to get an approximate √(2pi) value with only seven (!) valid digits:

Code:
÷ (355 ÷ 113 x 2) √x =

Why don't you simply use the exact value directly (even with less steps):

Code:
x ,3989422804 =

BTW, on a ten digit calculator multiplying by 1/√2pi is slightly more accurate than dividing by √(2pi) because the value rounds much better to ten digits.

Edit: But let's not bee too picky here. For large x the accuracy for Z(x) will lose up to three digits anyway. I also wonder if the 12C (Platinum) will accept the final digit 4 in the constant. Considering its internal 12-digit precision this might be the best way:

Code:
÷ 6,283185307 √x =

This should give 11 digits of √(2pi): 2,50662827460 instead of ...63.
Requires the same 11 steps as before, but has much better accuracy.

(12-01-2018 07:53 AM)Gamo Wrote:  Program: Normal Distribution (ALG Mode) 94 Program Lines

First of all: while Z(x) works for positive and negative x, the program calculates Q(x) only for x≥0. It does not handle negative x, for instance the program will return the same value for x=1 and –1. Here the user has to apply the formula Q(–x) = 1–Q(x) manually. Of course you can also make the program do so.

The cumulative distribution function Q(x) – the upper tail Normal integral – is approximated by a polynomial, the well-known Hastings approximation which for instance is listed in Abramovitz & Stegun, formula 26.2.17. But... the constants are rounded to six digits (probably due to the SR56's limited memory), so the accuracy of the original formula – a largest absolute error of 7,5 E–8 – is not met. That's why FIX 9 makes no sense here. For x≤2 the relative error is within 5 E–6, so you get about 5 valid significant digits. For larger x, similar to the original approximation, the number of valid digits decreases. For x=5 only three significant digits are left, and finally only two or one are correct.

The accuracy can be improved if the original untruncated coefficients are used:

p = 0,2316419
b1 = 0,31938153
b2 = -0,356563782
b3 = 1,781477937
b4 = -1,821255978
b5 = 1,330274429

This way you can set FIX 7, and what you see is correct within ±1 ULP. If the 12C Platinum does it like the original 12C, it will eventually switch to scientific notation. At this point you know you shouldn't trust more than two and finally only one significant digit: Try x=8, the exact Q-value here is 6,221 E–16 while the Hastings approximation with the above coefficients returns 6,285 E–16.

That's why I'd prefer a different way of calculating the Normal integral. For instance with a customized rational function. Same effort, better accuracy. ;-)

Here is such an approximation (for x≥0) that I set up some time ago:

Q(x) ≈ e–x²/2 · (1 + a1·x + a2·x² + a3·x³) / (2 + b1·x + b2·x² + b3·x³)

where
a1 = 0,433563
a2 = 0,084144052
a3 = -9,6367 E-5
b1 = 2,46295834
b2 = 1,13288719
b3 = 0,20590615

Again there are six constants, but with less digits. For x≤5 the largest relative error is less than 1,2 E–6, and the absolute error is < 1 unit in the 6th significant digit. For x>5 this approach is still better than Hastings'. For instance it returns Q(8) as 6,220 E–16. Near the end of the working range, at Q(21) = 3,28 E–98 the above method returns 3,26 E–98 while the Hastings approximation yields 3,56 E–98. All in all even at the underflow limit the relative error is less than 0,007.

But for large x you can apply a continued fraction method that keeps the error on the 1 E–6 level also for x>5. Actually the accuracy increases as x gets larger. I have also designed such a CF method that complements the above rational approximation and requires just three terms.

But I think I'm getting lost here... ;-)

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread (12C Platinum) Normal Distribution - Gamo - 12-01-2018, 07:53 AM RE: (12C Platinum) Normal Distribution - Dieter - 12-01-2018 10:59 AM RE: (12C Platinum) Normal Distribution - Albert Chan - 12-01-2018, 05:37 PM RE: (12C Platinum) Normal Distribution - Dieter - 12-01-2018, 07:44 PM RE: (12C Platinum) Normal Distribution - Albert Chan - 12-01-2018, 11:16 PM RE: (12C Platinum) Normal Distribution - Dieter - 12-02-2018, 09:11 AM RE: (12C Platinum) Normal Distribution - Dieter - 12-02-2018, 06:59 PM RE: (12C Platinum) Normal Distribution - Albert Chan - 12-02-2018, 08:14 PM RE: (12C Platinum) Normal Distribution - Dieter - 12-02-2018, 09:43 PM

User(s) browsing this thread: 1 Guest(s)