Post Reply 
HP 15C CE integration
09-20-2024, 04:08 PM
Post: #1
HP 15C CE integration
Hi everyone

I'm playing with my new HP 15C CE calculator. I tried an integration example from some Youtube video that compared two Casio calculators.

The following is output from Maxima of what is being evaluated:

Code:

(%i11) integrate(%e^(-(x^2)), x, 3, 65);     
                     sqrt(%pi) erf(65)   sqrt(%pi) erf(3)
(%o11)               ----------------- - ----------------
                             2                  2
(%i12) float(%);
(%o12)                        1.95771932368638e-5

I tried evaluating this on a $10 Casio fx-100MS, and got 0.00002 as the answer which is close.

Next, I tried the same on the HP 15C CE calculator. I first put it in "RAD" mode, then entered a saved program:

Code:

g P/R
f CLEAR PRGM
f LBL A
g x^2
CHS
e^x
g RTN
g P/R

Then, I tried to use the integrate function:

Code:

3
ENTER
65
f integrate-x-y
A

I get 8.5766e-14 as the result. This seems to be widely off what Maxima returns. Is there something wrong in what I entered?
Find all posts by this user
Quote this message in a reply
09-20-2024, 08:10 PM
Post: #2
RE: HP 15C CE integration
Hi and welcome to the forum !

The program you entered is correct.

However, on the HP-15C and its brothers, along with the DM-32, etc. you should evaluated integrals in SCI mode. So put the unit in SCI 4 or SCI 6, etc. and the answer will match.

FIX mode should really be avoided when evaluating integrals.

Good first post !

Gene
Find all posts by this user
Quote this message in a reply
09-20-2024, 11:37 PM
Post: #3
RE: HP 15C CE integration
HP's are using the display format as a guide to how accurate you need the answer to be. It's really smart, getting you what you need as quickly as possible. But when the result will be much less than 0, then FIX format is not the best to use.
Find all posts by this user
Quote this message in a reply
09-21-2024, 04:08 AM
Post: #4
RE: HP 15C CE integration
(09-20-2024 08:10 PM)Gene Wrote:  Hi and welcome to the forum !

Thank you Smile

Quote:The program you entered is correct.

However, on the HP-15C and its brothers, along with the DM-32, etc. you should evaluated integrals in SCI mode. So put the unit in SCI 4 or SCI 6, etc. and the answer will match.

FIX mode should really be avoided when evaluating integrals.

Thank you for pointing it out. I tried SCI 6 and it works well. I get 1.957719e-05, with a f-PREFIX of 1957719322. It took about 9 seconds in "running".

I tried SCI 9 and got 1.957719e-05 with a f-PREFIX of 1957719323 which matches Maxima till the last but one digit. Very good. It took about 37 seconds in "running".

Yesterday after posting my question (which was held for moderation as I'm a new member), I read the integration section in the owner's handbook as well as the advanced functions guide, esp. the part under "Evaluating Difficult Integrals" on page 57 in the advanced functions guide. It specifically mentions the e^-(x^2) case. This function flattens out to nearly 0 over almost the entire interval of [3, 65]. The manual recommended truncating it. With a smaller interval, it returned a closer result in even FIX mode (I didn't know SCI had to be used yesterday).

Yesterday I also came across this function's treatment in a William Kahan paper "Handheld Calculator Evaluates Integrals": https://web.archive.org/web/201203251147...980-08.pdf

(page 31)
Find all posts by this user
Quote this message in a reply
09-21-2024, 12:33 PM (This post was last modified: 09-21-2024 12:56 PM by AnnoyedOne.)
Post: #5
RE: HP 15C CE integration
(09-21-2024 04:08 AM)Idnarn Wrote:  ...I read the integration section in the owner's handbook as well as the advanced functions guide...

With older HP model calculators it is always advisable, IMO, to read the manual(s). They are not Casio's. A lot of stuff is explained.

A1

PS:
(09-21-2024 04:08 AM)Idnarn Wrote:  Yesterday I also came across this function's treatment in a William Kahan paper "Handheld Calculator Evaluates Integrals"...

I didn't have that but do now. Thanks. Knowledge is power.

HP-15C (2234A02xxx), HP-16C (2403A02xxx), HP-15C CE (9CJ323-03xxx), HP-20S (2844A16xxx), HP-12C+ (9CJ251)

Find all posts by this user
Quote this message in a reply
09-21-2024, 04:28 PM
Post: #6
RE: HP 15C CE integration
Bisecting to illustrate the effect of smaller intervals for this function, this time with Python sympy:
Code:
>>> from sympy import init_printing, Symbol, exp, integrate
>>> init_printing()
>>> x = Symbol("x")
>>> f = exp(-(x**2))
>>> integrate(f, (x, 3, 65)).n()
1.95771932367798e-5
>>> integrate(f, (x, 3, 32)).n()
1.95771932367798e-5
>>> integrate(f, (x, 3, 16)).n()
1.95771932367798e-5
>>> integrate(f, (x, 3, 8)).n()
1.95771932367798e-5
>>>

On the HP 15C CE, with [3, 8] even FIX 4 returned a reasonable solution (1.9458e-05). But I'll remember to use SCI when integrating.
Find all posts by this user
Quote this message in a reply
09-21-2024, 04:45 PM (This post was last modified: 09-21-2024 05:08 PM by AnnoyedOne.)
Post: #7
RE: HP 15C CE integration
No doubt you've discovered, by now, that this function is very similar to the Normal Distribution one discussed in the HP-15C Advanced Functions Handbook. It also contains a program to calculate that integral.

https://en.wikipedia.org/wiki/Normal_distribution

FYI in high school I tried to solve the integral analytically. I never succeeded and to my knowledge no-one else ever has either. The solutions I've seen are all numeric or polynomial approximations.

A1

HP-15C (2234A02xxx), HP-16C (2403A02xxx), HP-15C CE (9CJ323-03xxx), HP-20S (2844A16xxx), HP-12C+ (9CJ251)

Find all posts by this user
Quote this message in a reply
09-21-2024, 05:42 PM
Post: #8
RE: HP 15C CE integration
(09-21-2024 04:45 PM)AnnoyedOne Wrote:  FYI in high school I tried to solve the integral analytically. I never succeeded and to my knowledge no-one else ever has either.

That's no surprise due to Liouville's theorem:
Quote:The antiderivatives of certain elementary functions cannot themselves be expressed as elementary functions. These are called nonelementary antiderivatives. A standard example of such a function is \(e^{-x^{2}}\) whose antiderivative is (with a multiplier of a constant) the error function, familiar from statistics.
Find all posts by this user
Quote this message in a reply
09-21-2024, 05:46 PM
Post: #9
RE: HP 15C CE integration
(09-21-2024 05:42 PM)Thomas Klemm Wrote:  That's no surprise due to...

As any teenager will tell you (repeatedly) they're smarter than everyone else Smile

Until they "grow up" and realise that they aren't.

A1

HP-15C (2234A02xxx), HP-16C (2403A02xxx), HP-15C CE (9CJ323-03xxx), HP-20S (2844A16xxx), HP-12C+ (9CJ251)

Find all posts by this user
Quote this message in a reply
09-21-2024, 06:15 PM (This post was last modified: 09-22-2024 03:23 AM by carey.)
Post: #10
RE: HP 15C CE integration
(09-21-2024 05:42 PM)Thomas Klemm Wrote:  
(09-21-2024 04:45 PM)AnnoyedOne Wrote:  FYI in high school I tried to solve the integral analytically. I never succeeded and to my knowledge no-one else ever has either.

That's no surprise due to Liouville's theorem:
Quote:The antiderivatives of certain elementary functions cannot themselves be expressed as elementary functions. These are called nonelementary antiderivatives. A standard example of such a function is \(e^{-x^{2}}\) whose antiderivative is (with a multiplier of a constant) the error function, familiar from statistics.

Yes, while there is no closed-form solution to the integral of \( e^{-x^2} \) in terms of the elementary functions that appear on standard calculator keys, a closed-form solution exists in terms of special functions (e.g., the error function in this case).

Step 1: Start with the definition of the error function: \[\text{erf(x)} = \frac{2}{\sqrt\pi} \int_{0}^{x} e^{-t^2} \,dt\]

Step 2: Multiply both sides by \(\frac{\sqrt\pi}{2}\) and switch sides: \[ \int_{0}^{x} e^{-t^2} \,dt = \frac{\sqrt\pi}{2}\text{erf(x)} \]

Step 3: Convert the definite integral to an indefinite integral by the addition of a constant C. \[ \int {e^{-t^2}} \,dt \ = \frac{\sqrt\pi}{2}\text{erf(x)} + C \]

This is the closed-form solution of the integral in terms of the error function.

To check, we can evaluate this closed-form solution between limits of 3 and 65 as in the original question:

Since \(\text{erf(65)} \approx 1 \) and \(\text{erf(3)} \approx 0.99997791 \), the integral becomes:

\[ \int_{3}^{65} e^{-t^2} \,dt = \frac{\sqrt\pi}{2} \times (\text{1 - 0.99997791}) \]

\[ = 1.958 \times 10^{-5} \]

as expected.
Find all posts by this user
Quote this message in a reply
09-22-2024, 03:49 PM
Post: #11
RE: HP 15C CE integration
(09-21-2024 06:15 PM)carey Wrote:  Since \(\text{erf(65)} \approx 1 \) and \(\text{erf(3)} \approx 0.99997791 \), the integral becomes:

\[ \int_{3}^{65} e^{-t^2} \,dt = \frac{\sqrt\pi}{2} \times (\text{1 - 0.99997791}) \]

Perhaps it is better to skip subtraction, to avoid cancellation errors.
We may also use normal distribution functions.
Many scientific calculators had them, under statistics.

lua> x = 3
lua> sqrt(pi)/2 * erfc(x)
1.9577193236779756e-05
lua> sqrt(pi) * cdf(-sqrt(2)*x)
1.95771932367797e-05

65 treated as ∞, because ∫(e^(-t^2), t=65 .. ∞) ≈ e^(-65^2)/(2*65) ≈ 10^(-1837)
see A Continued Fraction for Error Function by Ramanujan, equation 3

Instead of treating upper limit as ∞, we may do opposite, make it as small as possible.

e^(-3^2)/(2*3) ≈ 2e-5
e^(-6^2)/(2*6) ≈ 2e-17

For 12 digits accuracy, integrate from 3 to 6 suffice.

>integ(3,6,1e-10,exp(-ix*ix))
1.95771932367E-5
Find all posts by this user
Quote this message in a reply
09-23-2024, 12:29 PM
Post: #12
RE: HP 15C CE integration
(09-22-2024 03:49 PM)Albert Chan Wrote:  Many scientific calculators had them, under statistics.

Unfortunately the only calculator I owned that did was the National Semiconductor NS-108. Very "soft" keys and a really poor power switch design. Don't bother buying one.

I do have programs for all my current calculators though. Numerical integration where possible, polynomial approximation where not. All better than 5 digits of accuracy. Better than the statistical tables I used in high school Smile

A1

HP-15C (2234A02xxx), HP-16C (2403A02xxx), HP-15C CE (9CJ323-03xxx), HP-20S (2844A16xxx), HP-12C+ (9CJ251)

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




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