rwg> n - 1 1/2 ==== / \ [ 1 d x i 1 - x i > I (- - x) (-- (g(- + -) + g(----- + -))) dx / ] 6 dx n n n n ==== / i = 0 0 ... = --------------------------------------------------, n
(directly verifiable by integration by parts). The individual integrals on the right are small. Can someone explain why?
It doesn't matter. They're large compared with their sums:
Testing with g(x):=4/(1+x^2), n = 1..4, [...] 8011 %pi - ---- = 3.35550919902339d-4 - 3.11524781089349d-4, 2550
829597 %pi - ------ = 3.48105078317297d-5 + 5.09316464365226d-5 264069 152916620159 - 8.48695005182994d-5, %pi - ------------ = 48674874300
7.09747270259224d-6 + 1.325010624272d-5 + 4.8192196463089d-6 - 2.5015667505753d-5]
(c347) resimplify(dfloat(%))
(d347) [0.00825932025646d0 = 0.00825932025646d0, 2.40261388126939d-5 = 2.402613881299d-5, 8.72653749706131d-7 = 8.72653749952849d-7, 1.51131086312262d-7 = 1.51131085868171d-7]
So this form of the error is unenlightening. rcs>Maybe 1/(1+x) would be a better test function, since 4/(1+x^2) has
only even-exponent terms in the power series? Before even trying it, I'll say no, since we're not 0-centered. E.g., we could pretend we did 1/(1 + i x) and took the realpart afterwards. OK, now let's compute 1 / [ 1 I ----- dx = log(2) = K(0, 1, 2, 3, 1, 6, 3, 1, 1, 2, 1, 1, 1, 1, 3, ] x + 1 / 0
10, 1, 1, 1, 2, 1, 1, 1, 1, 3, 2, 3, 1, 13, 7, 4, 1, 1, 1, 7, 2, 4, ...) by averaging 1/(1+x) over [0,1]. With nine samples, Thomas gives cf(''(makelist(1/(1+x),x,(0..8)/8).[1,4,2,4,2,4,2,4,1]/24)) [0, 1, 2, 3, 1, 6, 4, 1, 1, 2, 2, 5, 3, 1, 1, 1, 1, 1, 2] and with *ten*, Homer gives cf(''(makelist(1/(1+x),x,(0..9)/9).[1,3,3,2,3,3,2,3,3,1]/24)) [0, 1, 2, 3, 1, 6, 5, 8, 2, 1, 2, 1, 8, 2, 1, 1, 5] Worse, as predicted. On the other hand, the bizarreness with 7 32 12 32 7 giving -2 times the error with 1 4 1 may well depend on which function we're integrating, so 1/(1+x) will be good to test. rcs>Try just using one cycle for the whole integral: 11, 141, 1331, etc. I think "etc" needs defining. I calculated 7 32 12 32 7, <skipped>, and 41 216 27 272 27 216 41 to maximize the degree of the polynomial they integrate in one cycle (or any number). rcs> Is the convergence interesting? Does it? I don't think so. Recall in my previous msg that it took three periods of 41 216 27 272 27 216 41 (19 samples) to overtake 19 samples of 1 4 1. (And infinitely many periods of 7 32 12 32 7 ???) Maximizing the degree of approximation only pays off in the long run, if at all. With additional knowledge of the integrand, it should be possible to find 10 weights, say, that outperform both 1 3 3 2 3 ... 3 1 and whatever pattern exactly integrates x^10 + b x ^9 + ... . rcs>What happens if you stick with Simpson's 141, but move around the cut points (the abscissae)? Quodlibet. I guess you're asking how to move them for optimal approximation. As Webster's hints, the 1 4 1 really does integrate a piecewise parabolic fit, presupposing equal steps. For unequal steps you'd need different weights, although you could probably tailor the abscissae for specific integrands. That would be cheating. Gene>If I'm integrating over a circle, so that there is no boundary, then one point is as good as another, Not quite. Suppose we seek the average value (= 1/rt3) of 1/(2+sin(2(t+f) pi)), a smooth, period 1 fn(t) phase-shifted by the fraction f of a period. Then we can write the equal weight average exactly: (sum(1/(sin(%pi*(2*k/n+2*f))+2),k,0,n-1))/n = ((sqrt(3)+2)^n-(2-sqrt(3))^n)/(sqrt(3)*(-2*cos(%pi*(2*f+1/2)*n)+(sqrt(3)+2)^n+(2-sqrt(3))^n)) n - 1 ==== \ 1 > ----------------------- / 2 k ==== sin(pi (--- + 2 f)) + 2 k = 0 n ----------------------------- =: F(f) n n n (sqrt(3) + 2) - (2 - sqrt(3)) = ----------------------------------------------------------------- n n 1 ((sqrt(3) + 2) + (2 - sqrt(3)) - 2 cos(pi (2 f + -) n)) sqrt(3) 2 (Anybody want to hire me to make their CAS do these?) which does depend (slightly) on f. (And, ironically, is free of rt3.) For n = 1..6, 1 4 15 56 ---------------, ---------------, ----------------, ----------------, 2 + sin(2 f pi) 7 + cos(4 f pi) 26 - sin(6 f pi) 97 - cos(8 f pi) 209 780 ------------------, ------------------- 362 + sin(10 f pi) 1351 + cos(12 f pi) showing a dependence on f declining exponentially with n. Simpson's rule in this case is just F(f)/3 + 2 F(f+1/2n)/3, which is only slightly better, but has 2n samples, so is really worse! Gene>and I would expect the best approximation to be to give equal weights to each point. Now if instead, I integrate over an interval, there are some boundary effects, but deep within the interval , why would I want to do otherwise than to weight the points equally? This is a devilish question. But I don't think you can find any way of fading from 1,4,2,4,2,..., to 3,3,3,3,3,... and back to ...,2,4,2,4,1 that will exactly integrate cubics. Simpson's is geared to polynomials vs periodics. --rwg