Post Reply 
(50g) Normal Distribution
12-03-2018, 08:45 PM (This post was last modified: 12-03-2018 09:03 PM by John Keith.)
Post: #3
RE: (50g) Normal Distribution
Thank you for your valuable insights, Dieter.

(12-03-2018 07:05 PM)Dieter Wrote:  Yes, that's simple, but not a good idea. Try this for x=–10 to see why. ;-)

A better method that returns accurate results is this one (in pseudocode – you will know how to do this on the 50g):

Code:
p = UPTN(abs(x))
if x>0 then p = 1-p
return p

HP 50 version of above:
Code:

\<< UNROT PICK3 ABS UTPN SWAP 0. > { 1. SWAP - } IFT
\>>

(12-03-2018 07:05 PM)Dieter Wrote:  By the way, another useful function is the two-sided symmetric CDF A(x), i.e. the integral from –x to +x. Here similar considerations apply to get an accurate result for any x. If A(x) is calculated the tricky part is maintaining a decent accuracy for x close to 0, while for 1–A(x) the less trivial cases are those with large x. But this requires more than just a function for the upper or lower tail integral. What we need is an accurate value for the integral from 0 to x. Otherwise the trivial way of calculating A(x) = 1–2·UPTN(abs(x)) will suffer from digit cancellation for x<0,12566... As a rule of thumb, at x=10–n the last n digits are lost. But in praxi this admittedly is not much of a problem. And for x<10–6 you can simply set A(x) = x·√(2/pi). ;–)



3,14159265359? Does the 50g not have a constant for pi ?-)
Instead of 3,14159265359 you could directly code √(2pi) = 2,50662827463.

The HP 50 does have a constant pi but it is symbolic by default and converting it to a numeric value takes longer than the rest of the code to execute.
\pi \->NUM saves about 5 bytes over the in-line constant but I feel the extra memory is worth it if the code is to be executed inside a loop. Also, I cannot code √(2pi) directly because the actual formula is √(2*pi*v). The ... 2. * ... in the program is where the variance v is multiplied by 2.

(12-03-2018 07:05 PM)Dieter Wrote:  But, more important, this direct method is not exact for large x. The reason for the problem is explained more detailled in the HP67/97 program thread you have linked to. If you take a look at the program you will see a more elaborate method for calculating Z(x) which provides better accuracy.



Does the 50g also offer the inverse Normal CDF, i.e. the quantile function? Then you can also use this function to generate normally distributed random numbers.

Dieter

The HP 50 does not have inverse CDF functions, nor does it have a built-in command for normal RANDs. The Prime does have all of the above functions but I am trying to provide the missing ones for the HP 50.

I will look at your other suggestions when I have time but I fear some of them are "above my pay grade". Smile

John
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(50g) Normal Distribution - John Keith - 12-03-2018, 04:20 PM
RE: (50g) Normal Distribution - Dieter - 12-03-2018, 07:05 PM
RE: (50g) Normal Distribution - John Keith - 12-03-2018 08:45 PM
RE: (50g) Normal Distribution - Dieter - 12-03-2018, 10:18 PM
RE: (50g) Normal Distribution - John Keith - 12-03-2018, 10:59 PM
RE: (50g) Normal Distribution - John Keith - 12-04-2018, 08:54 PM
RE: (50g) Normal Distribution - Dieter - 12-04-2018, 09:48 PM
RE: (50g) Normal Distribution - Dieter - 12-05-2018, 08:49 PM
RE: (50g) Normal Distribution - John Keith - 12-06-2018, 02:58 PM
RE: (50g) Normal Distribution - Dieter - 12-06-2018, 11:08 PM
RE: (50g) Normal Distribution - John Keith - 12-07-2018, 11:21 PM
RE: (50g) Normal Distribution - Dieter - 12-06-2018, 10:54 PM
RE: (50g) Normal Distribution - John Keith - 12-08-2018, 07:13 PM
RE: (50g) Normal Distribution - Dieter - 12-08-2018, 09:18 PM
RE: (50g) Normal Distribution - John Keith - 12-08-2018, 09:28 PM
RE: (50g) Normal Distribution - John Keith - 01-26-2019, 10:01 PM
RE: (50g) Normal Distribution - pier4r - 01-26-2019, 10:12 PM



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