I was asked to use Romberg integration to evaluate the integral$$\int_0^1x^{-x}dx=\sum_{n=1}^\infty n^{-n}$$ and compare the result with the result I get from the sum. And I also need to estimate how many function evaluation Romberg integration will require to achieve 12 digit accuracy. I looked it up on Wikipedia but I still don't know how to estimate it using Romberg integration. And I guess that to achieve the accuracy, we could do that by looking into the error? Thanks!
-
Do you mean uniform Romberg integration, or adaptive quadrature using Richardson extrapolation to decide on the subintervals? The latter basically means: given a subinterval $[x,x+h]$, estimate the error in your current approximation by comparing it to the result of applying your rule to $[x,x+h/2]$ and $[x+h/2,x+h]$ and adding up the results. If this is larger than some tolerance, then consider these two subintervals and continue the procedure. – Ian Feb 29 '16 at 00:43
-
I think it's the latter one. I think it took me 12 steps to achieve 12-digit accuracy when evaluating the integral by computing the sum in that formula. So I am guessing it would also take me 12 steps using Romberg integration. I am computing R(1,1), R(2,1)...R(12,1), but according to the formula given on Wikipedia page, I got an extremely complicated answer for R(2,1), which makes it impossible for me to compute R(3,1).. – J.doe Feb 29 '16 at 00:49
-
You shouldn't be simplifying the formulas; you should express the formula of a given order in terms of the formula of the next order down. – Ian Feb 29 '16 at 00:50
-
I attached a screenshot of the method listed on Wikipedia. If I don't simplify the formula, how would I get the answer of each step? – J.doe Feb 29 '16 at 00:54
-
I computed that $R(1,1)=1/2$, and then for R(2,1), I get $1/4+1/4(f(1/4)+f(3/4))=1/4+1/4(\sqrt2 + 2\sqrt2/3^{3/4})$ – J.doe Feb 29 '16 at 00:56
2 Answers
This is not really an answer, but it is way too long for a comment. Here is an example of Romberg-type quadrature:
The base rule is a left hand Riemann sum on a uniform partition with subintervals of length $h=1$. The problem of interest is to integrate $e^x$ on $[0,1]$ with a tolerance of $10^{-1}$. So the final result should be somewhere between about $1.62$ and about $1.82$.
Our initial estimate is $1$, by implementing the base rule with $h=1$. We consider a refinement to $h=1/2$. This refinement would give an estimate of $\frac{1+e^{1/2}}{2} \approx 1.3$. This is too far from our initial estimate. The clever thing about Romberg integration is that instead of just using the value of the refinement, we can do a kind of weighted average of these two results to get an even better estimate. All we need to know is the order of our method (1 in this case). The idea is called Richardson extrapolation: if you have a function $T(h)$ representing the approximation of the desired value $I$ given by your method, then for a first order (convergent) method you have the expansion
$$T_1(h)=I + a_1 h + o(h)$$
where $h$ is the step size. Therefore
$$T_1(h/2)=I + a_1 h/2 + o(h)$$
Now $T_1(h)-2T_1(h/2)$ cancels out the linear terms, leaving $-I+o(h)$. Switching the sign gives $I+o(h)$, so we have a higher order method, namely $T_2(h):=2T_1(h/2)-T_1(h)$.
Returning to our example, this means we should try the estimate
$$2(e^0 \cdot 1/2 + e^{1/2} \cdot 1/2)-(e^0 \cdot 1)=e^0+e^{1/2}-e^0=e^{1/2} \approx 1.64.$$
$T_2$ is actually the midpoint rule, when simplified, but you don't need to know that (and in general such nice simplification doesn't occur).
To extrapolate further, we need to know the order of the midpoint rule, which is 2. So we look at Richardson extrapolation for order 2:
$$T_2(h)=I+a_2h^2+o(h^2) \\ T_2(h/2)=I+a_2h^2/4+o(h^2).$$
Therefore $T_2(h)-4T_2(h/2)=-3I+o(h^2)$, so $T_3(h):=\frac{4T_2(h/2)-T_2(h)}{3}$ is an even higher order method.
Now we need to calculate $T_3(1)$ in order to know whether to stop. We already took $T_2(1)$, it was $e^{1/2} \approx 1.6$. Now $T_2(1/2)$ is $e^{1/4} \cdot 1/2 + e^{3/4} \cdot 1/2 \approx 1.700$. So $T_3(1)$ is $\frac{2 e^{1/4} + 2 e^{3/4} - e^{1/2}}{3} \approx 1.718$. This is within $10^{-1}$ of our previous answer (about $1.64$), so we call this our final result.
I find it easier to work with this by just rederiving it through the Richardson extrapolation procedure rather than trying to learn any formulae.
By the way, this presentation is not adaptive. You get an adaptive variant by separately estimating the error on subintervals, and only using the higher order method on a given subinterval when the error estimate for that subinterval alone is too high.
- 101,645
-
So back to my question, I also need to compute $T_1(h), T_1(h/2), T_2(h),T_2(h/2)...$ till it achieves the accuracy? How is this different than the method R(1,1)...R(n,1) on wikipedia? – J.doe Feb 29 '16 at 01:25
-
@J.doe They are analytically equivalent; I just find this presentation easier to understand, especially as a newcomer. I find it especially helpful because it shows the crucial role played by the order of each method in the hierarchy. – Ian Feb 29 '16 at 01:25
-
Exactly, I found it easier as well. So I am going to use your method, instead of the one on wikipedia. The answer is gonna be the same right? – J.doe Feb 29 '16 at 01:27
-
@J.doe Yes (about the only thing that could change would be rounding errors due to different grouping of terms). – Ian Feb 29 '16 at 01:27
-
So $T_1(h)=1^{-1}\bullet 1=1$, but $T_1(h/2)= 0^0 \bullet 1/2+1/2^{-1/2}\bullet 1/2=\sqrt2 /2$? – J.doe Feb 29 '16 at 01:39
-
Be careful: when you write $0^0$ you want the limit of the integrated at zero which is 1. But otherwise yes. Note that you do not have to start with the rectangle rule; a common starting point is actually the trapezoidal rule, for instance. – Ian Feb 29 '16 at 01:57
-
But for this problem, the limit of the integrated at 0 is 1, since the limit as x approaches 0 of $x^x$ is 1, correct? – J.doe Feb 29 '16 at 22:54
-
-
I think I got it all wrong. $T_1(h)=0^0\bullet 1=1$ and $T_1(h/2)= 0^0\bullet 1/2+x^{-1/2}\bullet (1/2)$. Or should $T_1(h/2)$ be $0^0\bullet 1/2+x^{1/2}\bullet (1/2)$? – J.doe Feb 29 '16 at 23:08
-
It should be $1/2+(1/2)^{-1/2}/2$, which simplifies to what you had before. – Ian Mar 01 '16 at 00:05
-
I had $\sqrt2 /2$ before, but now I think the answer would be $(\sqrt 2 +1)/2$? – J.doe Mar 01 '16 at 00:20
-
Yes, $(\sqrt {2}+1)/2$. Now that is a fair bit bigger than 1 so you go again. – Ian Mar 01 '16 at 00:43
-
-
So for $T_3(h/2)$, I got $1/6^{-1/6}\bullet 1/2+ 5/6^{-5/6}\bullet 1/2$, but the answer seems incorrect. Why is that? – J.doe Mar 01 '16 at 02:45
-
You should be using x=0,1/4,1/2, and 3/4 with some weights. (Also, eventually you will want to just lower $h $ rather than continuing to extrapolate, because the very high order methods have impractically large coefficients $a_i$.) – Ian Mar 01 '16 at 11:27
-
Specifically, $T_3(1)=\frac{4T_2(1/2)-T_2(1)}{3}=\frac{4(2T_1(1/4)-T_1(1/2)-(2T_1(1/2)-T_1(1))}{3}=\frac{8T_1(1/4)-6T_1(1/2)+T_1(1)}{3}$. That writes it in terms of $T_1$; we can simplify further to write in terms of $f$, obtaining $\frac{\frac{8}{4} \sum_{i=0}^3 f(i/4)-\frac{6}{2} \sum_{i=0}^1 f(i/2)+f(0)}{3}=\frac{2 f(0)+2f(1/4)+2f(1/2)+2f(3/4)-3f(0)-3f(1/2)+f(0)}{3}=\frac{2f(1/4)-f(1/2)+2f(3/4)}{3}$. – Ian Mar 01 '16 at 14:16
-
-
I see. I am also asked to estimate how many function evaluation Romberg integration will require to achieve 12 digit accuracy. Is it safe to say that Romberg integration will require 12 functions to achieve 12 digit accuracy? – J.doe Mar 01 '16 at 20:22
-
@J.doe No. Unfortunately the answer depends on how exactly you perform the integration. There is a question of what your base rule is, how many extrapolations you perform, and what your step size(s) (plural if you use adaptivity) are. One nice thing in this case is that you can easily bound the error in the infinite sum ($\sum_{n=N}^\infty n^{-n} \leq \sum_{n=N}^\infty N^{-n}$, which you can explicitly calculate with the geometric series), so you can just keep working until you get close enough to the known value.) – Ian Mar 01 '16 at 21:34
-
I see thank you! I got another question and I am getting close to solve it, but there is just that one thing that keeps me from solving it. Would you be so nice to take a look at it? Thanks! http://math.stackexchange.com/questions/1676445/find-b-m-in-the-euler-maclaurin-summation?noredirect=1#comment3420616_1676445 – J.doe Mar 02 '16 at 00:12
Romberg integration involves successive subdivisions of the region of integration combined with extrapolation (from step $h$ to step $h/2$) to estimate the integral and get an approximation to the error.
It is usually done using a canned routine, but the formulas are simple enough that you should be able to implement it yourself.
What is your problem?
- 107,799
-
On wikipedia, it says "The zeroeth extrapolation, R(n, 0), is equivalent to the trapezoidal rule with 2n + 1 points; the first extrapolation, R(n, 1), is equivalent to Simpson's rule with 2n + 1 points. The second extrapolation, R(n, 2), is equivalent to Boole's rule with 2n + 1 points." For this question, what should I calculate? R(0,0) and R(1,1)? – J.doe Feb 29 '16 at 00:01
-
And can you also elaborate how to find that how many terms I need to evaluate to achieve 12-digit accuracy? Thanks! – J.doe Feb 29 '16 at 00:03
-
When the difference between two successive iterations is less than the desired error. – marty cohen Feb 29 '16 at 00:04
-
I know. So am I supposed to calculate all of the terms till they achieve 12-digit accuracy? I am thinking that maybe evaluating the error formula can be helpful? – J.doe Feb 29 '16 at 00:06
-
Look here for an example: https://en.wikipedia.org/wiki/Romberg%27s_method. The error estimate is the difference between the last two estimates. – marty cohen Feb 29 '16 at 00:11
-
-
Compute up to R(n, n) until |R(n, n)- R(n-1, n-1)| is small enough. – marty cohen Feb 29 '16 at 01:14
-
I used the method on Wikipedia, which I attached in my question, and I found that it is extremely hard to compute R(2,2) after finding R(1,1). – J.doe Feb 29 '16 at 01:26
