# Numerical integration of $\int_0^2 \frac{1}{x+4}dx.$

I have homework problem. Determine the number of intervals required to approximate $$\int_0^2 \frac{1}{x+4}dx$$ to within $10^{-5}$ and computer the approximation using (a) Trapezoidal rule, (b) Simpson's rule, (c) Gaussian quadrature rule. I think the phrase "within $10^{-5}$,"means that the error term.

I know that the m-point Newton-Cotes rule is defined by $$Q_{NC(m)}=\int_a^b p_{m-1}(x)dx,$$ where $p_{m-1}$ interpolates the function on $[a,b].$ So when $m=2,$ we call $Q_{NC(2)}$ trapezoidal rule, ans $Q_{NC(3)}$ is simpson's rule.

Can anyone explain what are these three rules and how I can proceed?? And what does $m$ represent?? Is it I am kind of lost in this class.. ans the text book is really really bad that I have no idea what it talks about...

yes, $10^{-5}$ is the error term. That is $$|I-I^{\prime}|$$ where $I$ is the exact integrand and $I^{\prime}$ is an approximation. I will summarize the methods as follows

Trapezoid is given by $$\int_{a}^{b}f(x)\,dx=(b-a)\frac{f(a)+f(b)}{2}$$ It approximates the integral by approximating the area under the curve like a trapezoid.

Simpson is given by $$\int_{a}^{b}f(x)\,dx=\frac{(b-a)}{6}\left(f(a)+4f\left(\frac{a+b}{2}\right)+f(b)\right)$$ and it is really a quadratic interpolation to approximate the integral.

Gaussian Quadrature is different in a sense that the integral is evlauted by picking certain points in interval with some weights. You an easily look up weights and points for GQ and it is given by $$\int_{-1}^{1} f(x)\,dx=\sum_{i=1}^{n} w_{i}f(x_{i})$$ For your exercise, start with a equally spaced points on the line and implement each of the above method. If the error is above the tolerance, increase the number of intervals and repeat the same process until the error is $\le 10^{-5}$. This will be few lines of code in your preferred language.

• I thought I first have to find inter polant and integrate it to find the error term. So given these rules, I just have to substitute the value of $f(x)$ and find approximation?? And What is the point of deviding the intervals?? How does that make the error smaller?? I think I need some more explanation!! Nov 19 '13 at 2:01
• Since the error is proportional to $(b-a)^5$, if you divide it into $n$ intervals, then the error in each interval goes down by a factor of $n^{-5}$. Since you then have to add up those $n$ intervals, that makes the error be multiplied by a factor of $n^{-4}$. So subdividing into intervals really helps a lot. Nov 19 '13 at 2:26
• So I first have to find the interpolants for each subinterval and add each $Q_{NC(m)}$?? If this is the case and $p_{m-1}(x) \approx f(x)$, then for each rule, do I substitute each $p_{m-1}(a)$ for $f(a)$ in any rule?? Nov 19 '13 at 2:40

It might also be asking you to use the remainder term formula. I happen to remember that the remainder term for Simpson's rule using $n$ intervals (where here $n$ must be an even number) is $$-\frac{(b-a)^5 f^{(4)}(\xi)}{180n^4}$$ where $a$ and $b$ are the limits of integration, $f$ is the integrand, and $\xi$ is between $a$ and $b$. But this will only get you a lower bound for an $n$ that guarantees the error is less than $10^{-5}$. There is a similar formula for the trapezoidal rule.

But I have absolutely no idea what it is for Gaussian quadrature!

• The actual error term in the book for Simpson's rule is $\left | \int_a^bf(x)dx-Q_{NC(3)} \right | \leq \frac{(b-a)^5}{2880}M_4,$ where $M_4$ is an upper bound for $f^{(4)}(x)$ on $[a,b].$ The question I have is that is the first step to solve it is to find the interpolant $p_{m-1}(x)$ and apply the rules?? Nov 19 '13 at 2:06
• That would be formula i wrote with $n = 2$. I think what they mean is that you find the interpolating polynomial that passes through $(a,f(a))$, $((a+b)/2,f((a+b)/2))$ and $(b,f(b))$. Then integrate that from $x=a$ to $x=b$. That will give you the formula felasfa gave you. Nov 19 '13 at 2:20
• But what felasfa is saying is to split the interval into $n$ equal pieces, and apply the formula to each piece, and then add them up. Nov 19 '13 at 2:22
• I use the notation from the book by Burden and Faires, which would say that what felasfa calls $n$ intervals, they call $2n$ intervals, because each interval $[a,b]$ is really two intervals $[a,(a+b)/2]$ and $[(a+b)/2,b]$. Nov 19 '13 at 2:23