HP 32sII Integration Error of Standard Normal Curve



#2

Hello, everyone.

When I integrate I usually use my graphing calculator so I haven't encountered any obstacles/errors. My favorite scientific calculator (the calculator I always have with me everywhere I go) is HP 32sII, and recently I decided to use its numeric integration capability. Specifically I integrated the standard normal curve, exp^(-z^2/2)/sqrt(2*pi)--it produced inaccurate results using the EQN method, but produced accurate results using the PRGM method.

The expression I entered in EQN is exp^(-z^2/2)/sqrt(2*pi), and when I integrate it from z=0 to z=1, the result is 0.4767 (the correct result should be 0.3413). Integrating over smaller ranges (like z=0 to z=0.1, z=0 to z=0.5, etc), the error starts to accumulate.

I also integrated the standard normal curve by programming it:

A01 LBL A

A02 π

A03 2

A04 ×

A05 SQRT

A06 1/x

A07 RCL Z

A08 x^2

A09 +/-

A10 2

A11 ÷

A12 e^x

A13 ×

The results of integrating the PRGM above of the standard normal curve are accurate.

I tried inputting the EQN and PRGM in HP 33s and HP 35s and the results are accurate.

I guess that's one of the reasons why the HP32sII was discontinued and better versions were conceived. It's a shame really, HP 32sII is the best among the last 3 great scientific calculators (HP 32sII, HP 33s, HP35s) that HP produced. HP 32sII has floating comma when inputting numbers, unlike the HP 35s. Number crunching is crisper in the 32sII, there's no worry that some buttons may not have registered (*cough* HP 35s *cough*), there's a large ENTER button unlike the miniscule ENTER button on the 33s. Entry of simple fractions, for example 3/4, is 3-decimal-decimal-4, not decimal-3-decimal-4 that 35s requires. Everything is so fluid in the HP 32sII...Ahh, sorry for the short spiel there, I'm just so passionate about the 32sII. :)

As a business-related student I use a financial calculator, too (HP 10bII+), and it has a "Z<>P" capability that converts z-scores to probabilities/areas under the standard normal curve, so I'm not that too hampered by my HP32sII's shortcomings, integration-wise.

Now that I'm on the topic of financial calculators, HP SHOULD MAKE a hybrid of HP32sII and HP 10bII+, an RPN scientific/financial calculator in which all the functions are accessible through the shift keys as opposed to having to invoke a menu to access such math functions like LOG. I love RPN, but I didn't gravitate towards the HP 30b when selecting my financial calculator because of that nuisance: in order to use the math functions like LOG, LN, etc, one would have to go through a menu. Oh, well.

Well, I just wanted to share the error in the HP 32sII to make everyone aware of its inaccurate integration of the standard normal curve.

Thanks.


#3

Anthony, the result 0.4767 you mentioned is correct for the integral from 0 to 1 of the function exp((-z)^2/2)/sqrt(2*pi), i.e. where -z (or z) is squared. So the problem most probably is caused by a somewhat incorrect function definition. BTW that's why the 35s uses two different characters for the operator "-" and the sign of a negative number. ;-)

So, you may simply try something like exp(-(z^2/2))/sqrt(2*pi). Or, much better, use one of the numerous other ways to evaluate the normal integral - as well as its inverse. I prefer rational approximations for both. Another approach is shown in the 15C Advanced Functions Handbook (p. 60 ff.) which uses an elegant variable transformation and the integrate function to obtain exact results for the normal integral even far out in the tails.

So there's nothing wrong with your 32s. It's just the usual precedence of the minus sign that is evaluated before the square. In other words: -z^2 is the same as (-z)^2 and not -(z^2). As far as I know most calculators work this way.

By the way: the 34s of course has functions for various statistical distributions and their inverse. The standard normal integral and its quantile function are directly accessible from the keyboard. With full 16-digit precision (or 32, if you wish) ;-)

Dieter

Edited: 13 Mar 2012, 6:51 p.m.


#4

Oh, but that's how I entered the expression in my other calculators, too:

exp^(-z^2/2)/sqrt(2*pi)

I get the correct 0.3413 result in all my calculators except the HP 32sII. I tried what you said, to input -(z^2/s), that is, to factor out the -1 outside the (-z^2/2) subexpression and the HP 32sII gives the correct 0.3413 result.

That leads to a troubling dilemma though...Why won't HP 32sII square the z-variable first then negate it, which is what it should do? Why is it negating z first then squaring it? In the expression (-z^2/2), which is equivalent to -1*z^2/2, the order of operations clearly dictate that exponents/powers (i.e., z^2) have to be evaluated first before multiplication/division (i.e., *-1 and /2)?

I'm looking at my HP 33s and HP 35s, and the expression I inputted is exp^(-z^2/2)/sqrt(2*pi), and they're correctly honoring the order of operations by squaring z first then negating it; I don't have to clearly factor out the -1 outside of the expression: -(z^2/2)

So, as a recap, by negating z first then squaring it, the expression exp^(-z^2/2)/sqrt(2*pi) is essentially being evaluated as exp^(z^2/2)/sqrt(2*pi) by HP 32sII.

Thank you for telling me this, now I'll make sure to


That's how I entered the expression in my other calculators, too:

exp^(-z^2/2)/sqrt(2*pi)

I get the correct 0.3413 result in all my calculators except the HP 32sII. I tried what you said, to input -(z^2/2), that is, to factor out the -1 outside the (-z^2/2) subexpression and the HP 32sII gives the correct 0.3413 result.

That leads to a troubling dilemma though...Why won't HP 32sII square the z-variable first then negate it (which is what it should do for the standard normal curve)? Why is it negating z first then squaring it (which is (-z)^2 = z^2)? In the expression (-z^2/2), which is equivalent to -1*z^2/2, the order of operations clearly dictate that exponents/powers (i.e., z^2) have to be evaluated first before multiplication/division (i.e., *-1 and /2)?

The result 0.4767 is being obtained by integrating exp^(+z^2/2)/sqrt(2*pi) from z=0 to z=1.

I'm looking at my HP 33s and HP 35s, and the expression I inputted is exp^(-z^2/2)/sqrt(2*pi), and they're correctly honoring the order of operations by squaring z first then negating it; I don't have to clearly factor out the -1 outside of the expression: -(z^2/2)

So, as a recap, by negating z first then squaring it, the expression exp^(-z^2/2)/sqrt(2*pi) is essentially being evaluated as exp^(z^2/2)/sqrt(2*pi) by HP 32sII.

Thank you for telling me this, now I'll make sure to add in extra sets of parentheses to make sure that HP 32sII is evaluating expressions correctly.

...

Hopefully I conveyed the problem clearly.

To sum up, the HP 32sII is evaluating the standard normal curve exp^(-z^2/2)/sqrt(2*pi) as if it's exp^(z^2/2)/sqrt(2*pi), because HP 32sII is treating (-z^2/2) as if it's (-z)^2/2.

HP 32sII is not honoring the order of operations. In the expression (-z^2/2) (which is the same as (-1*z^2/2)), z has to be squared first then negated (multiplied to -1) because exponents/powers are evaluated before multiplication/division. HP 32sII is negating z first then squaring the result after, which is not what it should do, rather, z should be squared first then the result negated after.

#5

Quote:


By the way: the 34s of course has functions for various statistical distributions and their inverse.



My first thought upon reading this (the original post refers to an 'older' calculator after all) was that your 34S reference had mistaken the 32E for the 34C, not realizing that HP was not the implied brand. The 32E has an extensive Statistical function set for a 1978 model. It includes Normal Distribution and Inverse Normal Distribution directly from the keyboard (Q and Q^-1). You can calculate your Z-Score with these. Useful for LeanSigma projects!

I have ordered my 30b chassis and look forward to having a latest version 34s soon.

#6

I can reproduce both your results with the HP-15c:

- the value of 0.4767 occurs if you negate z before squaring,

- while 0.3413 is obtained if you square z and then negate.

Try inserting parentheses around (z^2) in your formula:
i.e., exp^(-(z^2)/2)/sqrt(2*pi)

This is another case where RPN is nice as the ambiguities in operator precedence for a given implementation of infix notation do not occur.

Nick

Edited: 14 Mar 2012, 3:21 a.m.


Possibly Related Threads...
Thread Author Replies Views Last Post
  [HP Prime] "Error while checking exact value with approximate value, returning both!" Chris Pem10 13 681 12-06-2013, 05:12 AM
Last Post: parisse
  Integration question and "RPN" mode comment Craig Thomas 16 764 12-05-2013, 02:32 AM
Last Post: Nick_S
  MS advert shows spreadsheet with obvious error BruceH 3 290 11-14-2013, 09:50 AM
Last Post: Bill (Smithville, NJ)
  HP Prime: Rounding error in determinant Stephan Matthys 3 219 10-25-2013, 09:29 PM
Last Post: Walter B
  HP Prime Error: Summation Upper Bound > 1000 HP Pioneer 2 184 10-25-2013, 11:32 AM
Last Post: steindid
  Prime Error or Mine? toml_12953 12 592 10-22-2013, 10:35 AM
Last Post: toml_12953
  WP34s integration trapped in infinite loop Bernd Grubert 25 909 10-17-2013, 08:50 AM
Last Post: Dieter
  Explaination on How to Reset Caculator in Users guie: error Harold A Climer 5 311 10-15-2013, 02:11 AM
Last Post: cyrille de Brébisson
  Repair of HP-34C - Error 0 and Error 9 Jeff Kearns 3 233 10-11-2013, 12:29 PM
Last Post: Randy
  HP Prime integration Richard Berler 1 175 10-06-2013, 10:52 PM
Last Post: Helge Gabert

Forum Jump: