HP 42S, DM 42 Integral

02122021, 10:44 PM
Post: #1




HP 42S, DM 42 Integral
On my 42S, the integral of SIN X from 0 to 2pi produces 3.674E12 (very close to the actual answer of 0, using an accuracy of 1E5) nearly immediately.
My DM 42 takes a long enough time where I give up. Same 1E5 accuracy, even tried different accuracies ranging from .1 to 1E12 on the DM 42. My code is lbl “fx” MVAR X RCL X SIN X END Both the 42S and DM 42 very quickly come up with 2.000 Any idea as to why the DM 42 has trouble with the domain of (0,2pi) ? 

02122021, 10:46 PM
Post: #2




RE: HP 42S, DM 42 Integral
Meant to say both quickly come up with 2.000 for the integral from 0 to pi.


02122021, 10:58 PM
Post: #3




RE: HP 42S, DM 42 Integral
The fact that the actual integral is zero is causing the problem. INTEG waits for the relative error to drop below ACC, but when the true result is zero, the approximated result keeps getting smaller at the same rate as the absolute error estimate, and so the relative error doesn't get better. After a certain number of iterations, it just gives up, but since each iteration takes twice as long as the last one, the total number of times the function has to be evaluated gets large rather quickly.
In Free42, you won't notice this because it usually runs on hardware that is so fast that even evaluating the function tens of thousands of times only takes a moment, but on the DM42 this does become noticeable. Clearly the HP42S has a more aggressive termination condition for cases like this. 

02122021, 11:32 PM
Post: #4




RE: HP 42S, DM 42 Integral
(02122021 10:58 PM)Thomas Okken Wrote: The fact that the actual integral is zero is causing the problem. INTEG waits for the relative error to drop below ACC, but when the true result is zero, the approximated result keeps getting smaller at the same rate as the absolute error estimate, and so the relative error doesn't get better. More likely, integral results are bouncing around 0, thus unable to detect convergence. In other words, all it see is noise. 

02132021, 12:28 AM
Post: #5




RE: HP 42S, DM 42 Integral
(02122021 11:32 PM)Albert Chan Wrote:(02122021 10:58 PM)Thomas Okken Wrote: The fact that the actual integral is zero is causing the problem. INTEG waits for the relative error to drop below ACC, but when the true result is zero, the approximated result keeps getting smaller at the same rate as the absolute error estimate, and so the relative error doesn't get better. You're right. Adding print statements in INTEG showing the result and the error estimate after each iteration produces this: Code: INTEG "X" 

02132021, 01:38 AM
Post: #6




RE: HP 42S, DM 42 Integral
I am a bit surprised because I have observed the death spiral towards zero before, and I even thought it was with this specific test case. But apparently not!


02132021, 02:26 AM
Post: #7




RE: HP 42S, DM 42 Integral
Thanks for this! When I suspect this to be the case, I will add a 1  to the code, and verify that it converges on 1.


02132021, 03:03 AM
Post: #8




RE: HP 42S, DM 42 Integral
Adding 1E10 to the code made the DM 42 converge immediately on 2pi*1E10 which is what I was expecting on this example...had no awareness of the potential of a zero solution spiral on the DM 42...I believe that I have encountered this on an earlier occasion, but did not attempt to see if this happened on the 42S. The designer of the 42S algorithm must have been aware of this possibility. It appears as if, unfortunately, this was not taken into account on the DM 42!


02142021, 03:14 AM
Post: #9




RE: HP 42S, DM 42 Integral
Wondering...would the DM 42 be running the same integration algorithm as the 42S? I’m curious as to if the zero spiral phenomenon is due to a different platform or algorithm. It appears as if when the emphasis of what had been a large HP calculator group was focused more on an engineering audience, a lot of thought went into how each function performed over a full range of scenarios that might be encountered. The DM 42 is very beautiful achievement, but perhaps did not have the luxury of having a large team to optimize all of the functions that are offered. Happy to have both.


02142021, 03:27 AM
Post: #10




RE: HP 42S, DM 42 Integral
The DM42 firmware is basically Free42. The INTEG algorithm in Free42 is similar to that used in the HP42S, i.e. Romberg integration with nonuniform spacing of sample points, and very similar performance in terms of convergence and accuracy. The one significant difference is that the HP42S INTEG algorithm is smarter about when to stop the iteration...


02142021, 08:57 AM
(This post was last modified: 02142021 09:01 AM by JF Garnier.)
Post: #11




RE: HP 42S, DM 42 Integral
(02142021 03:27 AM)Thomas Okken Wrote: The INTEG algorithm in Free42 is similar to that used in the HP42S, i.e. Romberg integration with nonuniform spacing of sample points, and very similar performance in terms of convergence and accuracy. The one significant difference is that the HP42S INTEG algorithm is smarter about when to stop the iteration... The Romberg algorithm, as implemented in HP calculators starting with the 34C has no problem with null integrals by design, there are no special cases. In HP implementation, the termination condition is based on the sum of the absolute values of the samples. Is it the same in Free42? We discussed the HP algorithm last year, see here for some indications on the terminating condition. JF 

02142021, 02:22 PM
Post: #12




RE: HP 42S, DM 42 Integral
(02132021 01:38 AM)Thomas Okken Wrote: I am a bit surprised because I have observed the death spiral towards zero before ... It may be hard to see death spiral to 0, with INTEG utransformation, and romberg extrapolation. However, if we evaluate integral other ways, it is not hard to show one. \(\displaystyle AGM(a,b) = {(a+b)(\pi/4) \over K\left(k = {ab \over a+b}\right)} \) AGM(a,b) = arithmeticgeometic mean of a, b (above is equation 8) K = complete elliptic integral of first kind k = elliptic modulus (pi/2) / K(1) = AGM(2,0) = AGM(1,0) = AGM(1/2,0) = AGM(1/4,0) = ... = 0 Arithmetic mean forms a deathspiral toward zero. Thus, it may be better to test geometric mean convergence, AGM(2,0) = AGM(1,0) = 0 

02142021, 09:10 PM
Post: #13




RE: HP 42S, DM 42 Integral
(02142021 08:57 AM)JF Garnier Wrote: We discussed the HP algorithm last year, see here for some indications on the terminating condition. Thanks, I will look into that. It doesn't look like it would help with the death spiral scenario, but for the case at hand, where the approximation just bounces around, a better error estimate would definitely improve things, and allow the iteration to end much more quickly. 

02152021, 01:13 PM
Post: #14




RE: HP 42S, DM 42 Integral
A trick to detect bouncing around zero, or (rare) spiraling to zero, is flushing tiny result to 0
With sucessive integral estimates both zeroes, it now can detect convergence. 

02152021, 02:06 PM
Post: #15




RE: HP 42S, DM 42 Integral
The problem with that is that you don't know what "tiny" is.


02152021, 04:33 PM
Post: #16




RE: HP 42S, DM 42 Integral
(02152021 02:06 PM)Thomas Okken Wrote: The problem with that is that you don't know what "tiny" is. May be we do, if we estimate size of M = ∫(f(x), x= a .. b) OP example, F = ∫(sin(x), x= 0 .. 2*pi) M = ∫(sin(x), x= 0 .. 2*pi) = 4. (rough estimate OK) That meant rounding errors of M might be maximum of 4e33 (Free42 Decimal) x = a + k*h might also generate some errors, so above estimate of 'tiny' is not too bad. Any estimated F below 'tiny' might be considered 0. 

« Next Oldest  Next Newest »

User(s) browsing this thread: