Week 7: The Riemann Integral in 1D and 2D#
Key Terms#
The Riemann integral (the definite integral)
Subdivisions and mid-sums
The fundamental theorem of calculus
Anti-derivatives (the indefinite integral)
Partial integration and integration by substitution
Riemann integration of functions of two variables
Coordinate changes in 2D
Polar coordinates
Preparation and Syllabus#
Reading material: Sections 6.1 through 6.3
Python demo for week 7
Exercises – Long Day#
1: Anti-Derivatives to learn by Heart#
For which of the following functions can you immediately provide an anti-derivative?
\(x^n, \, n \in \mathbb{N}\)
\(\frac{1}{x}\)
\(\ln(x)\)
\(\frac{1}{1+x^2}\)
\(\cos(x)\)
\(\sin(x)\)
\(\exp(x)\)
For those where you had to give up, find an anti-derivative with SymPy’s integrate
, and then please add them to your long-term memory.
2: Eight Anti-Derivatives you must master#
State an anti-derivative for each of the following function:
\(x^n\,\) where \(n\) is an arbitrary constant in \(\mathbb Z\).
\(x^k\) where \(k\) is an arbitrary constant in \(\mathbb Q\).
\(\frac{1}{a\cdot x+b}\), where \(a\neq 0\) and \(b\) are arbitrary constants in \(\mathbb{R}\), and \(x\) belongs to a fitting interval.
\(\cos(a x+b)\) where \(a\neq 0\) and \(b\) are arbitrary constants in \(\mathbb{R}\).
\(f'(x)\) where \(f\) is differentiable.
\(\sin(ax+b)\) where \(a\neq 0\) and \(b\) are arbitrary constants in \(\mathbb{R}\).
\(\exp(a x+b)\) where \(a\neq 0\) and \(b\) are arbitrary constants in \(\mathbb{R}\).
\(\exp(a x+b)\) where \(a\neq 0\) and \(b\) are arbitrary constants in \(\mathbb{C}\).
Answer
Bullet 1: Assuming \(n>0,\) this is as in bullet 1 in Exercise 1: Anti-Derivatives to learn by Heart. Assuming \(n=0,\) we now must find an anti-derivative for the constant \(1\). Assuming \(n=-1,\) since \(x^{-1}=\frac 1x\) this is as in bullet 2 in Exercise 1: Anti-Derivatives to learn by Heart. Assuming \(n<-1,\) an example is \(\int u^{-3}\, \mathrm{d}u=\frac{1}{-3+1}u^{-3+1}=-\frac{1}{2}u^{-2}\) which shows that \(-\frac{1}{2u^2}\) is an anti-derivative for \(\frac{1}{u^3}\).
Bullet 2: Assuming \(k\neq -1,\,\) we have \(\,\int x^{\frac pq}\,\mathrm{d}x=\frac{1}{\frac pq+1}x^{\frac pq+1}\).
Bullet 3: \(\,\frac 1a \,\ln(a x+b)\)
Bullet 4: \(\,\frac 1a \,\sin(a x+b)\)
Bullet 5: \(f(x)\)
In similar fashions with bullets 6, 7 and 8.
3: Computational Rules for Anti-Derivatives. By Hand#
Determine the indefinite integral \(\int \left( 5\cos(x+1)-\sin(5x)+\frac{2}{x-3}-7\right)\,\mathrm{d}x\) for \(x>3\) and explain the computational rules you used along the way.
Answer
where \(C\in\mathbb R\) is an arbitrary constant.
4: The Fundamental Theorem. By Hand#
Question a#
Provide an anti-derivative for \(\frac{1}{1+x^2}\). Then compute the integral \(\int_0^1\,\frac{1}{1+x^2}\,\mathrm{d}x\).
Answer
An anti-derivative is \(\arctan\). The integral is \(\displaystyle{\frac{\pi}{4}}\).
Question b#
Compute the double integrals
and
Hint
First compute the inner integral while you treat \(y\) as was it a constant. Then do the outer integral with \(y\) as the integration variable.
Answer
Question c#
Let \(f: [-5,5] \to \mathbb{R}\) be given by
Compute
where \(x_{0}\in [-5,5]\) is fixed but arbitrary. Choose e.g. \(x_0=0\). Is \(F\) continuous? Is \(F\) differentiable at all points? Does \(f\) have an anti-derivative?
Hint
Use SymPy to help you out if you are stuck.
5: Parametrizations in the Plane#
Consider the sets \(V, U \subset \mathbb{R}^2\) given by
and \(U = B((0,0),2) \setminus \overline{B((0,0),1)}\), where \(B((0,0),r)\) is the open circle disc (also referred to as an open ball) with a radius of \(r\) centered at \((0,0)\), and \(\overline{B((0,0),r)}\) is the corresponding closed circle disc (where the boundary is included).
Question a#
Provide a parametrization \(\pmb{r}_1: [0,1]^2 \to V\) of \(V\). The vector function \(\pmb{r}_1\) must be a function of two variables, for example \((u,v) \in [0,1]^2\), and the image of \(\pmb{r}_1\) must be \(V\).
Note
The function \(\pmb{r}_1\) ought to be injective on the open set \(]0,1[^2\), although it is not a requirement.
Question b#
Provide a parametrization \(\pmb{r}_2: ]1,2[ \times [0,2\pi[ \to U\) of \(U\). The vector function \(\pmb{r}_2\) must be a function of two variables, for example \((r,\theta) \in ]1,2[ \times [0,2\pi[\), and the image of \(\pmb{r}_2\) must be \(U\).
Hint
Use polar coordinates as known from Mathematics 1a.
6: The Trapezoidal Rule and Riemann Sums#
Many integrals exist for which is it not possible to compute their “exact” values, often because their anti-derivatives cannot be expressed in terms of “known” functions. In this exercise we want to compute an approximated value of
The SciPy
package in Python can compute (approximations of) integrals using so-called numerical integration. We will here compare SciPy’s quad
method to both the Riemann sum that we know from the book and to the so-called trapezoidal rule.
The trapezoidal rule refers to the approximation to an integral over a small interval \([x_{j-1},x_j]\) given by
while we with mid-sums in the Riemann integral with the choice \(\xi_j:=\frac{x_j+x_{j-1}}{2}\) have
If one with the trapezoidal rule wants to approximate an integral over a larger interval \([a,b]\), one can subdivide it into several smaller intervals \(Q_j=[x_{j-1},x_j]\), \(j=1,\ldots,J\), and approximate on those individually, after which they can all be added together - precisely as for Riemann sums.
Question a#
Argue that \(\sin(x^2)\mathrm{exp}(3x)\) has an anti-derivative, and that the integral \(\int_0^3\sin(x^2)\mathrm{exp}(3x)\,\mathrm dx\) is well-defined. Try (in SymPy) to find the exact value of
Use .evalf()
to get an approximate value of the integral.
Hint
integrate(f(x),(x,0,3)).evalf()
Answer
Solution from SymPy:
It is probably possible to get SymPy as well as for instance Maple to provide an anti-derivative. But it will be expressed in terms of a function symbolised \(\mathrm{erf}\), which is not “known” to us nor does it have an “explicit” definition, and thus it does not provide us with any more information than the expression \(\int\sin(x^2)\mathrm{exp}(3x)\,\mathrm dx\).
Question b#
Compute the integral with quad
from scipy.integrate
. You must import from scipy.integrate import quad
and define
def f(x):
return sin(x**2)*exp(3*x)
Hint
from scipy.integrate import quad
def f(x):
return sin(x**2)*exp(3*x)
quad(f,0,3)
Answer
Question c#
We want to compare this with the Riemann integral that we have worked with previously. We use Riemann sums, where \([a,b]\) is subdivided into \(J\) equally large sub-intervals. Can you implement a function in Python that does this calculation for you? It must be of the form
def riemann(f,a,b,J):
where \(f\) is a continuous function, \(a\) and \(b\) are interval end-points, and \(J\) is the number of subdivisions of the integral. When you have written it you can test it on the same integral as above with \(J=20\).
Hint
It can look as follows:
def riemann(f,a,b,J):
w = (b - a)/J
x_v = a
result = 0
for i in range(J):
x_h = x_v + w
result += ???
x_v = x_h
result *= w
return result
You decide yourself how you wish to choose \(\xi_j\). In the above we have suggested choosing \(\xi_j\) as the mid-point of each subinterval.
Answer
An answer could be the following:
def riemann(f,a,b,J):
w = (b - a)/J
x_v = a
result = 0
for i in range(J):
x_h = x_v + w
result += f((x_h+x_v)/2)
x_v = x_h
result *= w
return result
Answer
Question d#
Using the trapezoidal rule we no longer approximate the area under a graph with a rectangle. Can you figure out how the shape looks based on the formula above?
Hint
See the figures here: https://en.wikipedia.org/wiki/Trapezoidal_rule.
Question e#
Now implement the trapezoidal rule:
def trapez_sum(f,a,b,J):
where \(f\) is a continuous function, \(a\) and \(b\) are the interval end-points, and \(J\) is the number of subdivisions of the integral. When you have written the program, you can test it on the same integral as above with \(J=20\).
Question f#
We do not seem to get the same value of the integral. Compare your results from Questions a, b, c, and e. Which method is better? Why? Also try with both more and fewer subdivisions of the interval.
7: An Indefinite Integral. By Hand#
Question a#
The following is not a Riemann integral: \(\int_0^1 \frac{1}{\sqrt{x}} \,\mathrm{d} x\). Why not?
Answer
The integral is not (it appears) well-defined since \(\frac{1}{\sqrt{x}}\) is not defined on \([0,1]\) (and thus not even continuous on \([0,1]\)). The integrand \(\frac{1}{\sqrt{x}}\) is, though, well-defined and continuous on \([a,1]\) for all values of \(0<a<1\), a fact that we will use in the next question.
Question b#
Compute \(\int_0^1 \frac{1}{\sqrt{x}} \,\mathrm{d} x\) as \(\lim_{a \to 0} \int_a^1 \frac{1}{\sqrt{x}} \,\mathrm{d} x\).
Hint
Determine \(\int_a^1 \frac{1}{\sqrt{x}} \,\mathrm{d} x\) and consider the limit at \(a \to 0\).
Answer
\(\int_0^1 \frac{1}{\sqrt{x}} \mathrm{d} x = \lim_{a \to 0} [2 \sqrt{x}]_a^1 = \lim_{a \to 0} (2-2\sqrt{a}) = 2\)
Question c#
Compute in a similar manner the integral \(\int_1^\infty \frac{1}{\sqrt{x}} \,\mathrm{d} x\) (if possible).
Hint
Determine the integral \(\int_1^b \frac{1}{\sqrt{x}} \,\mathrm{d} x\) and consider the limit at \(b \to \infty\).
Answer
The integral does not converge: \(\int_1^b \frac{1}{\sqrt{x}} \,\mathrm{d} x = [2 \sqrt{x}]_1^b = 2\sqrt{b} - 2 \to \infty\) when \(b \to \infty\).
8: Variable Substitution for an Integral in 2D#
Compute the integral
by performing a variable substitution.
Hint
Move \(1/x\) out of the fraction.
Answer
Hint
Variable substitution: \(z=y+1\).
Hint
After this variable substitution, the indefinite integral is written as
Answer
Exercises – Short Day#
1: Indefinite and Definite Integrals#
Question a#
Determine an anti-derivative for each of the functions
Hint
Note that the first example was treated in Exercise 1: Anti-Derivatives to learn by Heart and the two next ones in Exercise 2: Eight Anti-Derivatives you must master on Long Day.
Hint
In the second example, use the rewriting \(\displaystyle{\frac{1}{x^3}=x^{-3}}\).
Answer
Question b#
Compute the following Riemann integrals:
Answer
\(\frac{1}{4}, \frac{3}{8},\) and \(\frac{1}{3}\).
2: Partial Integration. By Hand#
Question a#
We will first prove the formula for partial integration. Begin by differentiating the expression on the right-hand side of
Hint
Remember how to differentiate the product of two functions.
Hint
Remember that differentiating \(\int h(x) \,\mathrm{d} x\) by definition gives \(h(x)\).
Now finish the proof.
Question b#
Determine an anti-derivative for the function \(x\cos(x)\), and check that it is correct.
Hint
Use partial integation where you choose \(f(x)=\cos(x)\) and \(g(x)=x\).
Hint
See the examples in the book.
Answer
An anti-derivative could be \(\cos(x)+x\sin(x)\). Since \((\cos(x)+x\sin(x))'=-\sin(x)+\sin(x)+x\cos(x)=x\cos(x)\), we have confirmed that the found anti-derivative really is an anti-derivative.
Question c#
Find an anti-derivative for \(\ln(x)\) using partial integration.
Hint
One can always multiply \(\ln(x)\) by \(1\) without changing the integrand.
Hint
Rewrite \(\ln(x)\) as \(f(x)\, \ln(x)\), where \(f(x)=1\).
3: Integration by Substitution#
For the questions in this exercise, use the substitution formula,
Question a#
Determine an anti-derivative for \(\displaystyle{x\mathrm{e}^{x^2}}\).
Hint
Can you identify an inner function \(g(x)\) and an outer function \(f(x)\)?
Hint
If we choose \(g(x)=x^2\) and \(f(x)=\mathrm{e}^x,\) we have \(f(g(x)) g'(x)=\mathrm{e}^{x^2} 2x=2(x\mathrm{e}^{x^2})\).
Answer
\(\displaystyle{\int{x\mathrm{e}^{x^2}\,\mathrm{d}x}=\frac 12\int{f(t)\,\mathrm{d}t}=\frac 12\mathrm{e}^t+C=\frac 12\mathrm{e}^{x^2}}+C\).
So, an anti-derivative is \(\frac 12\mathrm{e}^{x^2}}\).
Question b#
Determine the indefinite integral \(\displaystyle{\int \frac{x}{x^2+1} \,\mathrm{d}x}\).
Hint
Can you identify an inner function \(g(x)\) and an outer function \(f(x)\)?
Hint
If we choose \(g(x)=x^2+1\) and \(f(x)=\displaystyle{\frac{1}{x}},\) we have \(f(g(x))g'(x)=2\frac{x}{x^2+1}\).
Answer
Question c#
Find an anti-derivative for \(\displaystyle{\frac{\sin (x)}{3 -\cos(x)}}\), and then compute \(\displaystyle{\int_0^{\pi} \frac{\sin (x)}{3 -\cos(x)} \,\mathrm{d}x}\).
Hint
Choose \(g(x)\) to be the denominator.
Answer
\(\displaystyle{\int_0^{\pi} \frac{\sin (x)}{3 -\cos(x)} \,\mathrm dx = \ln(4)-\ln(2)=\ln(2)}\).
4: Sequences#
In this and the following exercise we are presenting samples of an important cornerstone of integral calculus: Sequences and their possible convergence. From the Danish encyclopedia Den Store Danske (publisher Gyldendal), translated:
convergence, term of fundamental meaning in mathematical analysis, especially in the theory of infinite series. A sequence of real numbers \(x_1,x_2,\ldots\) is called convergent if a number \(x\) exists such that the number \(x_n\) is arbitrarily close to \(x\) if just \(n\) is sufficiently large \((\ldots)\). The number \(x\) is called the limit value of the sequence, which is said to converge towards \(x\). If the sequence is not convergent, it is called divergent.
More precisely, a sequence \(x_1,x_2,\ldots\) is said to be convergent if a number \(x\) exists with the following property:
Four sequences \((a_n)_{n=1}^\infty\), \((b_n)_{n=1}^\infty\), \((c_n)_{n=1}^\infty\), and \((d_n)_{n=1}^\infty\) are given by
for \(n \in \mathbb{N}\). A sequence is in short form written as \((a_n)\) for \((a_1, a_2, \dots)\) and can be considered as an infinite ordered list.
Determine which of the four sequences that are convergent, and state the limit value for those that are.
Note
The term convergence is not only important in mathematical analysis. It is also the precise description of “engineering propositions” such as
Our algorithm/method/etc. converges if we just incorporate enough measurement points/data points/samples/etc.
Hint
If you cannot prove it from the definition, then try using Python for experimentation. You can quickly compute the first 100 or 1000 numbers in the sequence.
Answer
\((a_n)\) is convergent with the limit value \(0\). \((b_n)\) is convergent with the limit value \(\frac 12\). \((c_n)\) is divergent. \((d_n)\) is convergent with the limit value \(-\frac 43\).
5: Integrals via Left Sums#
We will compute the Riemann integral \(\displaystyle{\int_0^1 f(x) \,\mathrm{d}x}\) of the function
directly from the definition (so, do not find an anti-derivative such as \(F(x)=x^2/2\) and then compute \(F(1)-F(0)=1/2-0=1/2\)).
We subdivide the interval \([0,1]\) in \(n\) equally large pieces, meaning \(x_j=j/n\) for \(j=0,1,2,\dots, n\). The Riemann sum \(S_n\) is called a left sum \(V_n\), if we always evaluate \(f\) at the left end-point of each subinterval, so \(\xi_j = x_{j-1}\) for \(\xi_j \in [x_{j-1},x_j]\) for \(j=1,2,\dots, n\).
Using this, compute \(\displaystyle{\int_0^1 x\,\mathrm{d}x} = \lim_{n \to \infty} V_n\).
Hint
We must first find \(V_n\) expressed by only \(n\).
Hint
The rectangles have the areas \(\displaystyle{0,\frac{1}{n^2},\frac{2}{n^2},\frac{3}{n^2}\ldots\frac{n-1}{n^2}}\). What is the sum of these \(n\) terms?
Hint
Assume that \(n\) is odd. Ignore the first zero, then add together the second term and the last term, add together the third term and the second-to-last term, and keep up this pattern. This will in total be \((n-1)/2\) times that you will be adding together two terms.
Hint
Each sum of such two terms has the value \(n/n^2\), and you have \((n-1)/2\) of these. What is the total sum then?
Answer
In other words, we have