HP71B Integral Questions
|
02-08-2020, 10:46 AM
Post: #21
|
|||
|
|||
RE: HP71B Integral Questions
I'm still wrapping my head around my very long-term misunderstanding of hp's implementation of the Romberg method. So how does this work to use trapezoids but not evaluate the endpoints? Do you just leave out the two outermost trapezoids?
(If I'm not mistaken, I think you can also reuse previous samples for midpoints if you trisect the intervals.) |
|||
02-08-2020, 10:59 AM
Post: #22
|
|||
|
|||
RE: HP71B Integral Questions
(02-08-2020 10:46 AM)Wes Loewer Wrote: I'm still wrapping my head around my very long-term misunderstanding of hp's implementation of the Romberg method. So how does this work to use trapezoids but not evaluate the endpoints? Do you just leave out the two outermost trapezoids? Actually, the endpoints are not really left out, just it's useless to evaluate the function at the endpoints since their contribution to the sum is null due to the (1-u²) factor. So nothing is missing in the sum. J-F |
|||
02-08-2020, 03:04 PM
(This post was last modified: 02-09-2020 03:12 AM by Wes Loewer.)
Post: #23
|
|||
|
|||
RE: HP71B Integral Questions
(02-08-2020 10:59 AM)J-F Garnier Wrote: Actually, the endpoints are not really left out, just it's useless to evaluate the function at the endpoints since their contribution to the sum is null due to the (1-u²) factor. So nothing is missing in the sum. If the outside trapezoids don't contribute to the sum, isn't that equivalent to leaving them out? Wouldn't the approximate area of the outer intervals be missing from the sum? |
|||
02-09-2020, 01:43 PM
(This post was last modified: 02-09-2020 07:01 PM by Albert Chan.)
Post: #24
|
|||
|
|||
RE: HP71B Integral Questions
(02-07-2020 05:08 PM)Albert Chan Wrote: Since trapezoids and midpoints are using the same points, I tried to tease out the algorithm, using f(x) = x*log(1+x) Besides showing INTEGRAL algorithm using romberg's method with trapezoids, I noticed a few things.
Note: \(\int _{-1}^1 x \log(1+x)\;dx = 1\) We can prove using integration by parts, but is easier with symmetry \(\log(1+x) = \int _0 ^x {dt\over1+t} = \int _0 ^x (1-t+t^2-t^3+t^4+\;...) dt = {x\over1} - {x^2\over2} + {x^3\over3} - {x^4\over4} +\; ... \) \(\int _{-1}^1 x \log(1+x)\;dx = \int _{-1}^1 ({x^2\over1}-{x^3\over2}+{x^4\over3}-{x^5\over4}+\; ... )\; dx = 2 \int _0 ^1 ({x^2\over1} + {x^4\over3} + {x^6\over5} +\;...) dx \) Summing integrated terms, we have a telescoping series \({2\over1×3} + {2\over3×5} + {2\over5×7} + \;... = {1\over1}-{1\over3} + {1\over3}-{1\over5}+{1\over5}-{1\over7}+\;... = 1\) |
|||
02-09-2020, 08:33 PM
(This post was last modified: 02-09-2020 08:47 PM by Wes Loewer.)
Post: #25
|
|||
|
|||
RE: HP71B Integral Questions
Yes, I see what you mean. I get the same values as your tables.
(02-09-2020 01:43 PM)Albert Chan Wrote: [*] Even though the midpoint numbers does not incorprate previous sample points, it will, when we do the extrapolation. True, but the fact that for the midpoint method each new row has to start over from scratch is the very thing that makes it not as good as the trapezoid. If the previous points were reusable, then all midpoint values on your Romberg table would shift up by one row, making it the better option. This is the issue that I was missing in my thinking. Quote:For this example, extrapolated trapezoid numbers seems to converge with half the error. This makes perfect sense. The error bounds for midpoint and trapezoid methods are: |Em | < k(b-a)^3/(24n^2) and |Et | < k(b-a)^3/(12n^2) So for a given number of intervals (n) the midpoint method has about half the error of the trapezoid method. But for a given number of evaluation points, the trapezoid will have twice as many intervals, so now trapezoid will have about half the error. Just for fun, I wanted to see what would happen with Romberg using midpoints with trisected intervals, thereby allowing midpoints to reuse previous points. (If I did my Romberg calculations right, the only difference was changing 4^p-1 in the denominator to 9^p-1.) Here's what I get: Code: points midpoints with trisection This is only slightly better than the trapezoid method for this example. But for the previously mentioned problematic 1/sqrt(1-x^2), it makes a huge difference Code: points midpoints with trisection |
|||
02-09-2020, 09:03 PM
Post: #26
|
|||
|
|||
RE: HP71B Integral Questions
(02-08-2020 03:04 PM)Wes Loewer Wrote:(02-08-2020 10:59 AM)J-F Garnier Wrote: Actually, the endpoints are not really left out, just it's useless to evaluate the function at the endpoints since their contribution to the sum is null due to the (1-u²) factor. So nothing is missing in the sum. I see now why 1/sqrt(1-x^2) has such a difficult time converging with this algorithm. Every time the algorithm goes to a smaller interval, the total width being considered keeps growing. It's like trying to hit a moving target. For most functions, the cubic transformation will cause the endpoints to approach 0, so the added area has a shrinking height and width. But in this case, the endpoints approach a finite value (~1.73), so while the width is shrinking, the height is not. This has all been very educational. :-) |
|||
02-10-2020, 01:33 PM
(This post was last modified: 02-10-2020 01:35 PM by Albert Chan.)
Post: #27
|
|||
|
|||
RE: HP71B Integral Questions
(02-09-2020 08:33 PM)Wes Loewer Wrote:Quote:For this example, extrapolated trapezoid numbers seems to converge with half the error. The constant k of |Em| and |Et| are not the same k, but depends on actual curve. Even if the k's are the same, the formulas only give the upper bound, not equality. Also, INTEGRAL never return raw trapezoid numbers, but a minimum of 3 extrapolations. (even more extrapolations on top with more than 7 sample points). When I try compare errors of 2 methods, error ratios goes all over the place. The two schemes likely bracketed the true area (but, I also found exceptions) Example, from Kahan's article, Handheld Calculator Evaluates Integrals, page 30 f(x) = sqrt(x)/(x-1) - 1/log(x), x=0 to 1 → Et/Em ≈ -10 u-transformed f(x), u=-1 to 1 → Et/Em ≈ -0.4 u-transformed f(x), 2 times → Et/Em ≈ -0.06 Equivalent formula, with x=w^2 substitution: g(w) = 2*w^2/((w+1)*(w-1)) - w/log(w), w=0 to 1 → Et/Em ≈ -0.4 u-transformed g(w), u=-1 to 1 → Et/Em ≈ -0.05 u-transformed g(w), 2 times → Et/Em ≈ -0.02 to +0.02 Note: error ratios only consider final few iterations, initial numbers can go wild. u-transformation make the curve "bumpy", creating area strips errors of opposite signs, cancelling each other. If u-transformed more than once, area converge faster (at the cost of more time to evaluate functions). |
|||
02-11-2020, 05:03 PM
(This post was last modified: 04-14-2021 12:58 AM by Albert Chan.)
Post: #28
|
|||
|
|||
RE: HP71B Integral Questions
Trapezoid and midpoint extrapolated numbers are using same points.
Doing both schemes together in parallel are very cheap. Code: -- integ.lua Note: midpoints "first" simpson numbers were a placeholder, to line-up the 2 sequences. (1 sample point cannot produce simpson number, which required 3+ points) lua> I = require'integ' lua> log1p = require'mathx'.log1p lua> function f(x) return x*log1p(x) end lua> s = I.simpson(I.u(f,-1,1),-1,1,0) lua> a = I.integ(s) 4 0.9275194244636257 1.7390989208692982 8 0.9780170697704409 1.0269366636614183 16 0.9945010276157439 1.0108562045403804 32 0.9986339047563956 1.002758709871382 64 0.9996599242359795 1.0006854427294893 128 0.9999151793902487 1.0001704033854413 256 0.9999788205588988 1.0000424597853743 512 0.9999947084064521 1.0000105961327912 1024 0.9999986775131146 1.000002646612206 We don't know the error ratios of 2 methods. But, we can apply Aitken's Extrapolation for the better convergence sequence. In other words, extrapolate along the romberg table diagonals. For u-transfomed f(x), trapezoid numbers is better. ("error" between iterations is smaller) Aitkens extrapolation of last 5 trapezoid numbers gives area = 1.00000 000003 Code: 64 0.99965992424 For comparison, INTEGRAL (with built-in u-transform), and maximum 65536 intervals. >INTEGRAL(-1,1,0,IVAR*LOGP1(IVAR)) .999999 999665 |
|||
02-11-2020, 11:57 PM
Post: #29
|
|||
|
|||
RE: HP71B Integral Questions
Amazingly, Aitken's extrapolation trick work even for the troublesome 1/sqrt(1-x^2)
lua> I=require'integ' lua> function f(x) return 1/sqrt(1-x*x) end lua> u = I.u(f,-1,1) lua> a = I.integ(I.simpson(u,-1,1,0),2^10) -- with bad assumption, T1 = 0 4 2.6032971925091086 3.131182235954578 8 2.876452993708263 3.141072676119944 16 3.009535987413591 3.1415792702305954 32 3.075628788308323 3.1415925017013078 64 3.1086187748017564 3.141592652903347 128 3.1251067205395437 3.1415926535886425 256 3.1333498128442754 3.141592653589793 512 3.1374712489390655 3.141592653589794 1024 3.139531953229666 3.141592653589784 Code: Aitken Extrapolation on Trapezoid numbers As expected, with correct T1 value, trapezoid numbers converge better. lua> I.integ(I.simpson(u,-1,1,2*sqrt(3)),2^10) 4 3.1421574437527586 3.131182235954578 8 3.141606450669424 3.141072676119944 16 3.1415928071550314 3.1415792702305954 32 3.141592654278877 3.1415925017013078 64 3.141592653590944 3.141592652903347 128 3.1415926535897936 3.1415926535886425 256 3.1415926535897936 3.141592653589793 512 3.1415926535897944 3.141592653589794 1024 3.1415926535897887 3.141592653589784 |
|||
02-21-2020, 11:23 PM
(This post was last modified: 02-23-2020 01:55 AM by Albert Chan.)
Post: #30
|
|||
|
|||
RE: HP71B Integral Questions
Out of curiosity, I tried using the actual Gamma function integral
\(\Gamma(x+1) = \int _0 ^1 (-\ln(t))^x dt \) This integral, for any big x, choke on HP71B INTEGRAL Instead, I tried letting \(t = s^{x+1}\), turning the extreme spike into a bell-shaped curve \(\Gamma(x+1) = \int _0^1 (x+1) s^x (-(x+1)\ln(s))^x ds = (x+1)^{x+1} \int _0^1 (-s\ln(s))^x ds\) Scale RHS 2 terms to avoid hitting overflow limits, we have: Code: 10 P=1/10^8 >RUN X=?10 3623769.01194 -3.61915267163E-2 40.36 3628800.00001 12719498.961 .09 3628800 GAMMA(X+1) >RUN X=?20 1.66431877492E18 -15440997253.2 40.47 2.4329020082E18 4.16433765069E22 .11 2.43290200818E18 GAMMA(X+1) >RUN X=?30 1.39229859877E31 -1.13405116532E23 40.31 2.65252859812E32 1.55401137325E38 .19 2.65252859812E32 GAMMA(X+1) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)