HP Forums

Full Version: HP 42S Integration
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When integrating x^1/3 from -3 to 1, using
SIGN
LAST X
3
1/X
Y^X
ABS
*

The program, using ACC of 1e-5 was very much slowed down compared to the simpler program if the integral is calculated for a range falling entirely within a positive domain. The accuracy was also lessened.

On the Free42 on my iPad, the program for -3 to 1 ran quickly, and accuracy did not appear to be lessened. I did note that, even on the iPad, using an ACC of 1e-9 produced a noticeable delay in achieving an answer. I am left wondering what makes the program so much more time consuming, and why it impacts the accuracy on the physical calculator?
Because you calculate X^(1/3) for negative X, returning a complex answer, that you then turn into a real with ABS (this is where the accuracy is lost btw)
If you place the ABS in a different place, all will be well:

SIGN
LAST X
ABS
3
1/X
Y^X
x

Cheers, Werner
This is the issue:

(x^(1/3))' = (1/3) * x^(-2/3), which is infinite when x = 0

lua> Q = require'quad'
lua> Q.quad(cbrt, -3,1)
-2.4943671389852664       0.0017997781188810696       399
lua> Q.quad(cbrt, -3,-1)
-2.495061533191668        2.0824511484489283e-014      57
Thanks, Albert…I wonder how the Free42 integration implementation differs. Werner…your method produces a result equivalent to the integral from 0 to 3 + the integral from 0 to 1, not the intended domain of -3 to 1.
Hi Werner, I forgot to include the final “*” step in the program. The accuracy still suffers, but the integration seemed to be quicker. (Actual answer is ~-2.4951, using ACC of 1e-5, the HP 42S physical unit comes up with ~-2.4941) Free42 on my iPad is well within whatever ACC I assign.
One other note…when integrating from 3 to 0, and adding that to an integration from 0 to 1, accuracy is excellent, well within assigned ACC. ( I got ~-2.4951 (-2.49506 to 5 decimals)). This methodology produced a much quicker solution to the integration.
I should be clear in stating that I did simply integrated x^1/3 from 3 to 0 to get a negative area under the curve to then add to x^1/3 from 0 to 1 as an alternative means to avoid dealing with complex numbers in this example.
(11-09-2021 06:27 PM)lrdheat Wrote: [ -> ]Thanks, Albert…I wonder how the Free42 integration implementation differs.

Free42 integration routine use Romberg's method, with u-transformed integrand.

(11-10-2021 02:34 PM)lrdheat Wrote: [ -> ]I should be clear in stating that I did simply integrated x^1/3 from 3 to 0 to get a negative area under the curve
to then add to x^1/3 from 0 to 1 as an alternative means to avoid dealing with complex numbers in this example.

Complex numbers had little to do with the trouble of integrating it.
cbrt(x) = sign(x) * abs(x)^(1/3) will suffer just as badly, integrating from -3 to 1.

By examining trapezoid numbers, we can deduce effectiveness of Romberg's method.
Note: Q.tm returns trapezoids and squares area (mid-point as height, not used here)

lua> Q = require 'quad'
lua> t0, i0 = Q.tm(Q.u(cbrt,-3,0),-1,1), -3^(4/3) * 3/4
lua> t1, i1 = Q.tm(Q.u(cbrt,-3,1),-1,1), i0 + 3/4
lua> e0, e1 = {}, {}
lua> for i=1,9 do e0[i] = i0-t0(); e1[i] = i1-t1() end
lua> for i=2,9 do print(i, e0[i-1]/e0[i], e1[i-1]/e1[i]) end -- ratio of errors
Code:
2       4.406348748051959       -1.6536329825683571
3       4.201594378416317       -5.821460650747565
4       4.108589542455683       -0.882989199088926
5       4.062754066000128       10.74561334337938
6       4.037864315564835       -0.5274874702538931
7       4.023372017973919       3.095226872075786
8       4.014587966635934       14.259157703272143
9       4.009152913599486       -0.3493187427650485

For ∫(cbrt(x), x=-3..0), doubling trapezoids improve accuracy, about 4 times.

I = T1 + O(h^2)
I = T2 + O((h^2)/4

Assume both O(h^2) are close, we can extrapolate, and remove them.

4*I = 4*T2 + O(h^2) ≈ 4*T2 + (I-T1)
3*I ≈ 3*T2 + (T2-T1)
I = T2 + (T2-T1)/3 + O(h^4)

Rinse and repeat, we can remove O(h^4), O(h^6), O(h^8), ...
This is essentially what Romberg's method does.

For ∫(cbrt(x), x=-3..1), error ratios are all over the place, sometimes even wrong signs !

With false assumption, extrapolation make it worse.
Thanks, Albert!

Each integration strategy has it’s strength’s and weaknesses, yet I am amazed at how well they work for most problems. On the HP 42S, using an accuracy of 1e-5, most definite integrals can be solved in seconds, even with the much slower processor in the 30+ year old calculator!

I avoided the complex number difficulty by integrating x^1/3 from +3 to 0 (yielding a negative result), and adding that to the same integral from 0 to 1. This was much quicker and more accurate! I had been curious, though, about using the sign, abs means, and it is found to be less accurate and much slower!
Reference URL's