HP 42S Integration
|
11-09-2021, 03:23 PM
Post: #1
|
|||
|
|||
HP 42S Integration
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? |
|||
11-09-2021, 04:18 PM
Post: #2
|
|||
|
|||
RE: HP 42S Integration
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 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
11-09-2021, 05:06 PM
Post: #3
|
|||
|
|||
RE: HP 42S Integration
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 |
|||
11-09-2021, 06:27 PM
Post: #4
|
|||
|
|||
RE: HP 42S Integration
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.
|
|||
11-09-2021, 06:48 PM
Post: #5
|
|||
|
|||
RE: HP 42S Integration
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.
|
|||
11-09-2021, 06:55 PM
Post: #6
|
|||
|
|||
RE: HP 42S Integration
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.
|
|||
11-10-2021, 02:34 PM
Post: #7
|
|||
|
|||
RE: HP 42S 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-10-2021, 11:12 PM
Post: #8
|
|||
|
|||
RE: HP 42S Integration
(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 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 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. |
|||
11-10-2021, 11:53 PM
Post: #9
|
|||
|
|||
RE: HP 42S Integration
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! |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: robjordan, 1 Guest(s)