Week 7: Exercises#

The exercises are intended to be done by hand unless otherwise stated (such as when you are asked to plot a graph or run a script).

Exercises – Long Day#

1: Computational Rules for Antiderivatives#

Find 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 rules you have used along the way.

2: Using the Fundamental Theorem of Calculus#

Question a#

We are informed that \(\frac{\mathrm d}{\mathrm dx}(\arctan)(x) = \frac{1}{1+x^2}\). Provide all antiderivatives of \(\frac{1}{1+x^2}\). Then calculate the integral \(\int_0^1\frac{1}{1+x^2}\mathrm{d}x\).

Question b#

Calculate the double-integrals

\[\begin{equation*} \int_1^2\Big (\int_0^1\frac{\mathrm{e}^{2x}}{y}\mathrm{d}x\Big)\mathrm{d}y \end{equation*}\]

and

\[\begin{equation*} \int_0^{\frac{\pi}{2}}\Big (\int_0^1y\cos(xy)\mathrm{d}x\Big)\mathrm{d}y. \end{equation*}\]

Question c#

Let \(f: [-5,5] \to \mathbb{R}\) be given by

\[\begin{equation*} f(x) = \begin{cases} 1 & \text{for } x \in [0,1] \\ 0 & \text{for } x \in [-5,5] \setminus [0,1]. \end{cases} \end{equation*}\]

Calculate:

\[\begin{equation*} F(x) = \int_{x_{0}}^{x} f(y) \mathrm{d} y \quad \text{for $x \in [-5,5]$}, \end{equation*}\]

where \(x_{0}\in [-5,5]\) is fixed but arbitrary. You can i.e. choose \(x_0=0\). Is \(F\) continuous? Is \(F\) differentiable at all points? Is \(F\) an antiderivative of \(f\)?

3: Parametrizations in the Plane#

Consider the sets \(U \subset \mathbb{R}^2\) given by

\[\begin{equation*} U = B((0,0),2) \setminus \overline{B((0,0),1)}, \end{equation*}\]

where \(B((0,0),r)\) is an open circular disc with radius \(r\) and center \((0,0)\), and \(\overline{B((0,0),r)}\) is the closed circular disc (so, including the boundary).

Make a sketch of the set \(U\). Provide a parametrization \(\boldsymbol p:\,\,]1,2[\,\times[0,2\pi[\,\,\to U\) of \(U\). The vector function \(\boldsymbol p\) must be a function of two variables, i.e., \((r,\theta)\in\,\,]1,2[\,\times [0,2\pi[\,\), and the image set of \(\boldsymbol p\) must be \(U\).

4: Riemann Sum for a Linear Function#

We are given the function \(f:[0,5] \rightarrow \mathbb{R}\) by the expression \(f(x)=2x+3\).

Question a#

Use Python to find a value of the Riemann sum over the interval \([0,5]\) with 30 subintervals, where the left endpoints of the subintervals are used. Then repeat for the right endpoints of the subintervals.

Question b#

Find the exact values of the Riemann sum over the interval \([0,5]\) with \(n\) subintervals, where the left endpoints of the subintervals are used. Then repeat for the right endpoints of the subintervals.

Note

You may use, without proof, that \(\sum_{k=1}^n k = n(n+1)/2\). (You are of course welcome to try to prove this formula, but that is not a part of this exercise. The idea behind such proof is to pair-wise sum up first the first with the last terms, then the second with the second-last, etc.)

Question c#

Show that the error \(∣\int_0^5 ​f(x)\mathrm dx−R_n​∣\) for both the leftsum and the rightsum (here denoted by \(R_n\)) are bounded by the expression \(n/C\)​. Determine the constant \(C\).

Question d#

Argue, in this specific case, that the Riemann sum has the same limit value regardless of the choice of point in the subinterval.

5: The Trapezoidal Method and Rieman Sums#

There are many integrals that cannot be calculated exactly, often because the antiderivative cannot be expressed by a “known” function. In this exercise, we wish to calculate an approximate value for:

\[\begin{equation*} \int_0^3 \sin(x^2) \exp(3x) \mathrm{d}x. \end{equation*}\]

The SciPy package in Python can compute (approximations of) integrals using so-called numerical integration. Here, we will compare SciPy’s quad command with both the Riemann sum we know from the book and the so-called trapezoidal method.

By the trapezoidal method we mean the approximation to the integral over a small interval \([x_{j-1},x_j]\) given by

\[\begin{equation*} \int_{x_{j-1}}^{x_{j}}f(x)\mathrm{d}x=\frac{1}{2}(x_{j}-x_{j-1})(f(x_{j-1})+f(x_{j})), \end{equation*}\]

while we by mid-sums of the Riemann integral with the choice \(\xi_j := \frac{x_{j}+x_{j-1}}{2}\) have

\[\begin{equation*} \int_{x_{j-1}}^{x_{j}} f(x)dx\approx f(\xi_j) (x_{j}-x_{j-1}). \end{equation*}\]

If you want to approximate an integral over a larger interval \([a,b]\), you can subdivide it into several smaller intervals \(Q_j=[x_{j-1},x_j]\), \(j=1, \dots, J\), and approximate them individually, after which you can sum them all together – just like with Riemann sums.

Question a#

Argue that \(\sin(x^2) \exp(3x)\) has an antiderivative and that the integral \(\int_0^3 \sin(x^2) \exp(3x) \, \mathrm{d}x\) is well-defined. Try (in SymPy) to find the exact value of

\[\begin{equation*} \int_0^3 \sin(x^2) \exp(3x) \mathrm{d}x. \end{equation*}\]

Use .evalf() to get an approximate value of the integral.

Question b#

Calculate the integral using quad from scipy.integrate. You must import from scipy.integrate import quad and define:

def f(x):
    return sin(x**2)*exp(3*x)

Question c#

We would like to compare this with the Riemann integral we have worked with earlier. We use Riemann sums, where \([a,b]\) is divided into \(J\) equal subintervals. Can you implement a function in Python that calculates this for you? It should have the following form:

def riemann_sum(f,a,b,J):

where \(f\) is a continuous function, \(a\) and \(b\) are the inteval endpoints, and \(J\) is the number of subdivisions of the integral. When you have written your Python function, you can test it on the same integral as above with \(J=20\).

Question d#

With the trapezoidal method we no longer approximate the area under a graph with rectangles. Can you figure out what the shape looks like based on the formula above?

Question e#

Now implement the trapezoidal method:

def trapez_sum(f,a,b,J):

where \(f\) is a continuous function, \(a\) and \(b\) are the interval endpoints, and \(J\) is the number of subdivisions of the integral. Once you’ve written your code, you can test it on the same integral as above with \(J=20\).

Question f#

It doesn’t immediately seem like we get the same value of the integral. Compare your results from questions a, b, c and e. Which method is the best? Why do you think so? Also, try both with more and fewer subdivisions of the interval.

6: An Integral in 2D#

We wish to calculate the integral

\[\begin{equation*} I = \int_{0}^1\int_1^8\frac{y}{x+xy}\mathrm{d} x\mathrm{d}y. \end{equation*}\]

First, argue that the integrand can be written as a product of a function that only depends on \(x\) and a function that only depends on \(y\). Then, find the value of \(I\).

7: An Indefinite Integral#

Question a#

The following is not a Rieman integral:

\[\int_0^1 \frac{1}{\sqrt{x}} \mathrm{d} x.\]

Why not?

Question b#

Calculate \(\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\).

Question c#

Find in a similar fashion the integral \(\int_1^\infty \frac{1}{\sqrt{x}} \mathrm{d} x\) (if possible).

Exercises – Short Day#

1: Indefinite and Definite Integrals#

Question a#

Determine an antiderivative of each of the functions

\[\begin{equation*} x^3, \quad \frac{1}{x^3} \quad \text{and} \quad \sin(3x-\frac{\pi}{2}). \end{equation*}\]

Question b#

Calculate the following Riemann integrals:

\[\begin{equation*} \int_0^{1}x^3\mathrm{d}x, \quad \int_1^{2}\frac{1}{x^3}\mathrm{d}x \quad \text{and} \quad \int_{-\frac{\pi}{2}}^{0}\sin(3x-\frac{\pi}{2})\mathrm{d}x. \end{equation*}\]

2: Partial Integration#

Question a#

We will first prove the formula for partial integration. Begin by differentiating the expression on the right-hand side of

\[\begin{equation*} \int f(x)g(x)\mathrm{d}x = F(x)g(x)- \int F(x)g^\prime(x) \mathrm{d} x. \end{equation*}\]

Now finish the proof.

Question b#

Determine an antiderivative of the function \(x\cos(x)\), and check that it is correct.

Question c#

Find an antiderivative of \(\ln(x)\) using partial integration.

3: Integration by Substitution#

For the questions in this exercise we will use the method known as integration by substitution:

\[\begin{equation*} \int{f(g(x))g'(x)\mathrm{d}x}=\int{f(t)\mathrm{d}t}\quad \text{where } t=g(x). \end{equation*}\]

Question a#

Determine an antiderivative of \(\displaystyle{x\mathrm{e}^{x^2}}\).

Question b#

Find the indefinite integral \(\displaystyle{\int \frac{x}{x^2+1} \mathrm{d}x}\).

Question c#

Find an antiderivative of \(\displaystyle{\frac{\sin (x)}{3 -\cos(x)}}\), and then calculate \(\displaystyle{\int_0^{\pi} \frac{\sin (x)}{3 -\cos(x)} \mathrm{d}x}\).

4: Sequences#

In this and the following exercises, we are given samples of an important building block for integral calculus: sequences and their potential convergence. From Den Store Danske (Gyldendal dictionaries), translated:

Convergence, a concept of fundamental importance in mathematical analysis, especially in the theory of infinite series. A sequence of real numbers \(x_1, x_2, \ldots\) is called convergent if there exists a number \(x\) such that the number \(x_n\) is arbitrarily close to \(x\), as long as \(n\) is sufficiently large (\(\ldots\)). The number \(x\) is called the limit (or limit value) of the sequence, which is said to converge to \(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 there exists a number \(x\) with the following property:

\[\begin{equation*} \forall \epsilon >0 \exists N \in \mathbb{N}: n \ge N \Rightarrow |x_n -x| < \epsilon. \end{equation*}\]

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

\[\begin{equation*} a_n=\frac 1n, \: b_n=\frac{n-1}{2n}, \: c_n=\frac{n}{1000} \:\text{and}\; d_n=\frac{4n^2+16}{8-3n^2} \end{equation*}\]

for \(n \in \mathbb{N}\). A sequence is written in short as \((a_n)\) for \((a_1, a_2, \dots)\) and can be considered an infinite ordered list.

Determine which of the four sequences are convergent. Specify the limit of those that are convergent.

Note

The concept of convergence is not only important in mathematical analysis. It is also the precise description of “engineering statements” such as:

Our algorithm/method/etc. converges if we simply include enough measurement points/data points/samples/etc.

5: Integrals via Left-Sums#

We will calculate the Riemann integral \(\displaystyle{\int_0^1 f(x) \mathrm{d}x}\) of the function

\[\begin{equation*} f(x)=x, \quad x\in \left[0,1\right] \end{equation*}\]

directly from the definition (so, do not find an antiderivative \(F(x)=x^2/2\) and then use it to calculate \(F(1)-F(0)=1/2-0=1/2\)).

We subdivide the interval \([0,1]\) into \(n\) equally large pieces, i.e., \(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 endpoint of each subinterval, that is, \(\xi_j = x_{j-1}\) for \(\xi_j \in [x_{j-1}, x_j]\) for \(j = 1, 2, \dots, n\).

Use this to determine the value of \(\displaystyle{\int_0^1 x \, \mathrm{d}x} = \lim_{n \to \infty} V_n\).