HP Forums
WP 34S on DM 42 integral fail - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not quite HP Calculators - but related (/forum-8.html)
+--- Thread: WP 34S on DM 42 integral fail (/thread-18253.html)



WP 34S on DM 42 integral fail - lrdheat - 04-12-2022 07:06 PM

When integrating from -2 to 3 the function 1/3Root(x), my WP 34S comes up with 0. The answer should be ~.739. I use an 8 size stack and full precision. My code is LBL ‘F0’, FILL, 3Root(x), (1/x), RTN


RE: WP 34S on DM 42 integral fail - lrdheat - 04-12-2022 07:20 PM

Of course, if I break it into 2 integrals, from (-2 to 0) + from (0 to 3), I come up with the correct result quickly. I am curious as to why the WP 34S could not deal with using the -2 to 3 domain, and if this is unexpected.


RE: WP 34S on DM 42 integral fail - ijabbott - 04-12-2022 09:57 PM

I guess it has something to do with the discontinuity between the bounds.


RE: WP 34S on DM 42 integral fail - lrdheat - 04-12-2022 11:35 PM

My TI-30X Pro had no problem with the integration, did not require breaking the integral into two…


RE: WP 34S on DM 42 integral fail - Steve Simpkin - 04-13-2022 12:38 AM

My TI-89 and HP Prime (IOS App) provided the correct answer just fine. My Casio fx-991EX and fx-CG50 both gave a Math Error.


RE: WP 34S on DM 42 integral fail - Thomas Klemm - 04-13-2022 12:52 AM

From xrom/integrate.wp34s:
Quote:// - the double exponential method relies on the function to be
// integrated being analytic over the integration interval, except,
// perhaps, at the interval ends. Thus, if it is known that the
// integrand, _or any of its derivatives_, has a discontinuity at some
// point inside the integration interval, it is advised to break the
// interval at such point and compute two separate integrals, one
// at each side of the problematic point. Better results will be
// get this way. Thus, beware of abs, fp, ip and such non analytic
// functions inside the integrand program. Other methods (Romberg)
// may behave better in this respect, but, on the other side, the
// double exponential method manages discontinuities (of the
// integrand or its derivatives) at the interval edges better and
// is usually way faster that the Romberg method

In this specific case you can just integrate from 2 to 3.
Also you can skip the FILL command in your program.


RE: WP 34S on DM 42 integral fail - lrdheat - 04-13-2022 03:51 AM

Re Steve…I have been surprised that the CASIO fx-CG50 cannot handle discontinuities where an integration would be a finite result. If the discontinuity is at 0 for example, one is forced to use 1*10^-12 for a starting point. Also surprised that it cannot handle trig or exponential commands with complex numbers, does not calculate prime factors, does not have a product command to complement the summation capability. Still, and excellent calculator. Really shines with graphing, graphing analysis, fantastic labeling of the x and y axis, Great with regressions and distributions! Fast as well.


RE: WP 34S on DM 42 integral fail - J-F Garnier - 04-13-2022 08:55 AM

Already discussed here ?

J-F


RE: WP 34S on DM 42 integral fail - lrdheat - 04-13-2022 02:28 PM

Wow! I forgot about this…other nice examples, remedies given as well!


RE: WP 34S on DM 42 integral fail - Albert Chan - 04-13-2022 04:00 PM

(04-12-2022 11:35 PM)lrdheat Wrote:  My TI-30X Pro had no problem with the integration, did not require breaking the integral into two…

Maybe it did "break" integral into two (or more pieces), see Adaptive quadrature

Example, gaussquad() use adaptive Gaussian quadratures with 15 points.

XCas> gaussquad(surd(x,3), x=-2..3.)

1.35517995835


RE: WP 34S on DM 42 integral fail - lrdheat - 04-13-2022 05:42 PM

I’m integrating the reciprocal of your function…this results in an undefined point at x=0.

This produces, if correct, ~.7379


RE: WP 34S on DM 42 integral fail - Albert Chan - 04-13-2022 07:38 PM

XCas> gaussquad(surd(x,-3), x,-2.,3.)

0.739024156625

This work ! But, I would advice split the integral yourself, to be safe.
Adaptive scheme may be fooled. (no matter how good it is, it only see sample points)

Below is adaptive simpson's scheme to do above integral.
Note line 150. It never touched undefined point at x=0
(But, if integral limits changed, say, -2 .. 6, it will hit x=0 dead on)

10 X1=-2 @ X3=3 @ E=.0001
20 T=TIME @ X2=(X3+X1)/2 @ CALL F(X1,F1) @ CALL F(X2,F2) @ CALL F(X3,F3)
30 S=(F1+4*F2+F3)*(X3-X1)/6
40 CALL SIMPSON(X1,X2,X3,F1,F2,F3,32*E,S) @ DISP S,TIME-T @ END
50 SUB F(X,Y) @ Y=SGN(X)*ABS(X)^(-1/3) @ STOP

100 SUB SIMPSON(X1,X3,X5,F1,F3,F5,E,S)
110 H=(X5-X1)/4 @ X2=X1+H @ X4=X5-H
120 CALL F(X2,F2) @ CALL F(X4,F4)
130 H=H/3 @ S1=(F1+4*F2+F3)*H @ S2=(F3+4*F4+F5)*H
140 S3=S1+S2 @ D=S3-S @ H=E/2
150 IF H<1.E-15 OR ABS(D)<H THEN S=S3+D/15 @ STOP
160 CALL SIMPSON(X1,X2,X3,F1,F2,F3,H,S1)
170 CALL SIMPSON(X3,X4,X5,F3,F4,F5,H,S2)
180 S=S1+S2

>RUN
 .73902427614      18.76

Update: slightly modified SIMPSON() recurse condition, with following:

40 CALL SIMPSON(X1,X2,X3,F1,F2,F3,30*E,S) @ DISP S,TIME-T @ END
150 IF H<15E-15 OR ABS(D)<H THEN S=S3+D/15 @ STOP

> RUN
 .73902420507      15.44

The changes is to compare Sharp BASIC translated HP71B code speed.