Exercise bank

Lecture 1

Exercise 1.1

Add a new markdown cell below this one and write β€œHello world!”

Exercise 1.2

Compute \(\eta\) for approximating \(e\) with \(3\), \(2.7\), and \(2.718\).

Exercise 1.3

Show that \(\frac{n + \cos(n)}{n^2} = O(\frac1n)\) and \(\frac{n^2+3}{n^{42}} = O(\frac1{n^{40}})\).

Exercise 1.4

Let \(e\) denote Euler’s constant.

  1. \(e_N := \big( 1 + \frac{1}{N} \big)^N\) is an approximation \(e\). What is the error, absolute error, and relative error in approximating \(e\) with \(e_N\) for \(N = 1,2,...,10\)? What are the number of accurate digits in this approximation?
  2. What is the rate of convergence of \(e_N\) to \(e\)?

Exercise 1.5

Euler-Mascheroni constant, \(\gamma\), is defined as the limit of \(\gamma_n = \sum_{k=1}^n \frac{1}{k} - \log n\) as \(n \to \infty\).

  1. What is the absolute error in approximating \(\gamma\) with \(\gamma_{1000}\)?
  2. What is the rate of convergence of \(\gamma_n\) to \(\gamma\)?
  3. [This was just so that we can remember some calculus and also rigorously prove the rate of convergence that we have seen above using a rigorous error estimate]
    Prove that \(|\gamma - \gamma_n| \leq \frac1n\).

Exercise 1.6

Assignment 1, Fall 2025, 30 pts The quantities

\[\begin{align} \pi_N := 4 \sum_{n=0}^N \frac{(-1)^n}{2n+1} \end{align}\]

approximate \(\pi\) by using the Taylor expansion of \(\arctan\) together with the fact that \(\pi = 4 \arctan(1)\).

Code
using Plots, LaTeXStrings

Nmax = 100;
Ninter = 1:Nmax;

# vectors of length Nmax
p = zeros( Nmax ); q = zeros( Nmax );
p[1] = 4 * ( 1 - 1/3 ) ;
q[1] = abs( p[1] - Ο€ );
for N in 2:Nmax
    p[N] = p[N-1] + 4 * (-1)^N/(2*N + 1);
    q[N] = abs( p[N] - Ο€ );
end

plot(p, legend=false, xlabel="N", title=L"\pi_N")

Based on the following graph, what is the rate of convergence of this particular approximation to \(\pi\)? Why do we use a log-log scale for this graph?

Code
plot( q , xaxis=:log, yaxis=:log, xlabel=L"N", title="absolute error", legend=false)
plot!( Ninter.^(-1) , ls=:dash)

Lecture 2

Exercise 2.1

In England, when we need to convert between lb and kg some people use the phrase β€œ2.2 pounds of jam is the same as a kilogram”.

  • What is the error, absolute error, and relative error of approximating 1 kg with 2.2 lb?
  • To how many significant digits is this approximation correct to?

You may use 1 kg = 2.20462262185 lb.

Exercise 2.2

Most people say a marathon is 26 miles when it is actually 26 miles 385 yards. In Europe, people say a marathon is 42 km when it is actually 42.194988 km.

  • Which approximation has a smaller error?
  • What is the advantage of computing the relative errors in this case?

Hint: You may use the fact that 1 mile \(=\) 1760 yards.

Exercise 2.3

The astronomical unit is defined as \(1 \text{AU} = 149,597,870,700 \text{m}\). Write this in standard form.

Exercise 2.4

Write down all the floating point numbers with \(k = 2\) in the interval \([1,2)\). What about the interval \([2,4)\)? \([2^n,2^{n+1})\)?

Exercise 2.5

Take \(k=\ell=2\).

  • What number does \(0 0 1 1 0\) encode?
  • Write the bitstring of \(-3.5\).
  • What are the maximum and minimum positive (normal) numbers and the machine precision in this system?

Exercise 2.6

What are the maximum and minimum positive numbers and the machine precision for each of Float16, Float32, and Float64?

Exercise 2.7

Write down the bitstring for \(\pi\) in Float16.

Exercise 2.8

Compute the relative condition numbers of (i) \(x \mapsto cx\) for \(c \not= 0\), (ii) \(\log(x)\), (iii) \(\exp\), (iv) \(x^p\), and (v) \(f\circ g\) in terms of \(\kappa_f\) and \(\kappa_g\)

Exercise 2.9

Midterm, Fall 2025, Compulsory Section, 3 pts. Let us define

\[\begin{align*} f(x) = \frac{\sqrt{1+x}-1}{x}, \qquad g(x) = \frac{1}{\sqrt{1+x} + 1}. \end{align*}\]

One may verify that \(f\) and \(g\) are mathematically identical (but you don’t have to). The following table is the output of evaluating \(f\) and \(g\) on \(\{10^{-14}, 10^{-15}, 10^{-16}\}\) in double precision floating point. Why are the function values different?

Code
f = x -> ( sqrt(1 + x) - 1 ) / x
g = x-> 1/( 1 + sqrt(1 + x) )

t = [1e-14; 1e-15; 1e-16];
   
println( "                         f(x)                  g(x)" )
println( "x = 10^(-14):     ", f(t[1]), "    ",    g(t[1]) )
println( "x = 10^(-15):     ", f(t[2]), "   ",    g(t[2]) )
println( "x = 10^(-16):     ", f(t[3]), "                   ",    g(t[3]) )
                         f(x)                  g(x)
x = 10^(-14):     0.4884981308350689    0.4999999999999988
x = 10^(-15):     0.44408920985006256   0.4999999999999999
x = 10^(-16):     0.0                   0.5

Quiz 0

Quiz 0: Exercise 1

Let \(x_n = \frac{1 + n^2}{ 2 n^3 } \cos n\). For which of the following sequences \((\varepsilon_n)\) do we have \(x_n = O(\varepsilon_n)\) as \(n\to\infty\)? Select all that apply.

(a). \(\varepsilon_n = e^{-n}\), (b). \(\varepsilon_n = n^{-2}\), (c). \(\varepsilon_n = n^{-1}\), (d). \(\varepsilon_n = 1\), (e). \(\varepsilon_n = n\).

Quiz 0: Exercise 2

Let us define

\[\begin{align*} f(x) = \frac{\sqrt{1+x}-1}{x}, \qquad g(x) = \frac{1}{\sqrt{1+x} + 1}. \end{align*}\]

One may verify that \(f\) and \(g\) are mathematically identical (but you don’t have to). The following table is the output of evaluating \(f\) and \(g\) on \(\{10^{-14}, 10^{-15}, 10^{-16}\}\) in double precision floating point. Why are the function values different?

Code
f = x -> ( sqrt(1 + x) - 1 ) / x
g = x-> 1/( 1 + sqrt(1 + x) )

t = [1e-14; 1e-15; 1e-16];

println( "                         f(x)                  g(x)" )
println( "x = 10^(-14):     ", f(t[1]), "    ",    g(t[1]) )
println( "x = 10^(-15):     ", f(t[2]), "   ",    g(t[2]) )
println( "x = 10^(-16):     ", f(t[3]), "                   ",    g(t[3]) )
                         f(x)                  g(x)
x = 10^(-14):     0.4884981308350689    0.4999999999999988
x = 10^(-15):     0.44408920985006256   0.4999999999999999
x = 10^(-16):     0.0                   0.5

Lecture 3

Exercise 3.1

Let \(\epsilon\) be the machine precision. Is \((1 + \epsilon/2) - 1 = 1 + (\epsilon/2-1)\) in Float64?

Exercise 3.2

Let \(X\) be an array containing \(10^{16}, -10^{16}\), and \(N\) copies of \(1\). What is the sum of all the entries of the array \(X\)? Does it depend on the order of summation? What about in Float64? Why?

Exercise 3.3

Exercise 1.4.1 from Driscoll and Braun (2017), [Fundamentals of Numerical Computation by Driscoll, Braun]

Exercise 3.4

Exercise 1.4.2 from Driscoll and Braun (2017), [Fundamentals of Numerical Computation by Driscoll, Braun]

Exercise 3.5

Let \(f(x) = e^x - 2x - 1\). Apply change of sign theorem to \(f\) to conclude there exists \(\xi \in [1,2]\) such that \(f(\xi) = 0\).

Exercise 3.6

Let’s return to Exercise 3.5. You showed that \(f(x) = e^x - 2x - 1\) has a root \(\xi \in [1,2]\).

Show that \(f(x) = 0\) can be solved by instead considering the fixed point problems \(g(x) = x\) or \(h(x) = x\) where

\[ \begin{align} g(x) &= \log( 2x + 1 ), \\ h(x) &= \frac{e^x - 1}{2}. \end{align} \]

Show that Brouwer’s fixed point theorem applies to \(g\) but not \(h\) on \([1,2]\).

Exercise 3.7

Assignment 1, Fall 2025, [30 pts]. Prove that, for \(x \geq 0\), there exists a unique \(W(x) \geq 0\) for which \(W(x) e^{W(x)} = x\). Show that \(\Omega := W(1)\) satisfies \(0.56 < \Omega < 0.58\).

Exercise 3.8

Assignment 2, Fall 2025, [10 pts]. For fixed \(f\), define

\[\begin{align} g(x) &= f(x - a), \\ h(x) &= b f(x), \\ j(x) &= f(c x), \end{align}\]

  1. What is \(\kappa_g(x)\)?
  2. Write \(\kappa_{h}(x)\) in terms of \(\kappa_f\),
  3. Write \(\kappa_{j}(x)\) in terms of \(\kappa_f\),
  4. What is \(\kappa_f(x)\) when \(f(x) = e^{-x^2}\)?

Exercise 3.9

Assignment 2, Fall 2025, [25 pts]. Consider the differential equation (initial value problem)

\[ \begin{align} \begin{split} u'(x) &= u(x) +e^{-x} \nonumber \\ u(0) &= -\frac12 . \end{split} \end{align} \]

  1. Show that \(u(x) = -\frac12 e^{-x}\) solves (3.2).

Now we perturb the initial data, by considering

\[ \begin{align} \begin{split} u'(x) &= u(x) +e^{-x} \nonumber \\ u(0) &= \alpha \end{split} \end{align} \]

for \(\alpha := \epsilon - \frac12\).

  1. Show that \(u_{\alpha}(x) = (\alpha + \frac12) e^x -\frac12 e^{-x}\) solves (3.3).
  2. Plot the functions \(u\) and \(u_{\alpha}\) and comment on the difference between the solutions for large \(x\).
  3. Let \(f( \alpha ) = u_\alpha( 100 )\). What is the condition number \(\kappa_f( \alpha )\)?
  4. Explain what happens for \(\alpha \approx -\frac12\). Link your observations to your answer for question 3.

Exercise 3.10

Assignment 2, Fall 2025, [10 pts]. Let \(p_{\alpha}(x) = \alpha x^n + \sum_{j=0}^{n-1} a_{j} x^j\) be a polynomial of degree \(n\) and let \(r(\alpha)\) be a root of \(p_{\alpha}\). What is the condition number \(\kappa_r(\alpha)\)?

Lecture 4

Exercise 4.1

Suppose \(g :[a,b] \to \mathbb R\) is continuously differentiable with \(|g'(x)| \leq L < 1\) for all \(x \in [a,b]\). Show that \(g\) is a contraction with constant \(L\).

Exercise 4.2

Take the simple iteration \(x_{n+1} = g(x_n)\) for some contraction \(g : [a,b] \to [a,b]\). Show that \((x_n)\) converges to the fixed point of \(g\) in \([a,b]\) at least linearly with asymptotic error constant \(\mu = |g'(\xi)|\).

Exercise 4.3

Show that \(g(x) = \log( 2x + 1)\) is a contraction on \([1,2]\) with \(L = \frac23\). Hence conclude that \(x_{n+1} := g(x_n)\) converges for all \(x_1 \in [1,2]\).

Exercise 4.4

Assignment 2, Fall 2025, [25 pts]. Fix \(a, x_1 > 0\) and define the iteration \(x_{n+1} = \frac{1}{2}\big( x_n + \frac{a}{x_n} \big)\).

  1. ✍ Show that \(x_{n+1}\) has the same sign as \(x_n\),
  2. ✍ Suppose that \((x_n) \to \xi\). What is the value of \(\xi\)?
  3. πŸ’» Let \(x\) be as in question 2. Show numerically that \((x_n) \to \xi\) for a few different choices of \(a\) and \(x_1\),
  4. πŸ’» This iteration can be seen as a way of approximating \(\xi\). What is the correseponding order of convergence?

Exercise 4.5

Assignment 3, Fall 2025. The Lambert W function (also called the product-log function) \(W : [0,\infty) \to [0,\infty)\) satisfies \(W(a) e^{W(a)} = a\). Define \(\Omega := W(1)\).

  1. ✍ Show that \(\Omega \in [0.56, 0.58]\).
  2. ✍ Show that \(\Omega\) is a fixed point of \(g\) and \(h\) as defined by

\[\begin{align} g(x) = e^{-x}, \qquad h(x) = \log \left|\frac{1}{x}\right| \end{align}\]

  1. πŸ’» Show numerically that \(x_{n+1} = g(x_n)\) converges and \(y_{n+1} = h(y_n)\) diverges for a few different choices of \(x_1\) and \(y_1\).
  2. ✍ Show that \(g:[\frac{1}{e}, 1]\to[\frac{1}{e},1]\) with \(|g'| < 1\),
  3. ✍ Explain why this means that the iteration \(x_{n+1} = g(x_n)\) converges for all \(x_1 \in [\frac{1}{e}, 1]\),
  4. ✍ Now fix \(x_1 \in \mathbb R\). Show that the sequence \((x_n)\) is eventually contained in \([0,1]\) and that \(g : [0,1] \to [\frac{1}{e}, 1]\). Explain why this means that \((x_n)\) converges for all \(x_1 \in \mathbb R\),
  5. ✍ What is the order of convergence of this method?
  6. πŸ’» Confirm this numerically.
  7. ✍ Show that \((y_n)\) doesn’t converge to \(\Omega\) for any choice of \(y_1 \not= \Omega\).

Exercise 4.6

Midterm, Fall 2025, Optional section, 30 pts. Define \(g(x) = 1 + \frac{1}{1 + x}\) and \(I := [1,2]\).

  1. [3 points] Show that \(g(x) \in I\) for all \(x \in I\).
  2. [3 points] Which theorem guarantees the existence of a fixed point \(\xi = g(\xi) \in I\).
  3. [3 points] Compute the value of \(\xi\).
  4. [3 points] Show that \(L := \max_{x \in I} |g'(x)| = \frac14\).
  5. [3 points] Explain why this means the iteration \(x_{n+1} = g(x_n)\) converges to \(\xi\) for all \(x_1 \in I\).
  6. [5 points] What is the order of convergence?
  7. [5 points] What is the asymptotic error constant?
  8. [5 points] Fix \(x_1 \in I\). Find \(n\) for which the error bound \(|x_{n+1} - \xi| \leq \frac{1}{64}\) is guaranteed.

Quiz 1

Quiz 1: Exercise 1

Let \(x_n = \frac{1 + n^2}{ 3 n^4 } \cos n^5\). For which of the following sequences \((\varepsilon_n)\) do we have \(x_n = O(\varepsilon_n)\) as \(n\to\infty\)? Select all that apply.

  • \(\varepsilon_n = e^{-n}\),
  • \(\varepsilon_n = n^{-2}\),
  • \(\varepsilon_n = n^{-1}\),
  • \(\varepsilon_n = 1\),
  • \(\varepsilon_n = n\).

Quiz 1: Exercise 2

Note that \(x := 1.001^{2026}\) and \(y := e^{2026 \log 1.001}\) are mathematically identical (\(x=y\)). In the following code, we use 16 bit floating point arithmetic to compute \(x\) (by repeated multiplication) and \(y\) (with the above formula):

Code
b, n, x = Float16( 1.001 ), 2026, Float16( 1 );
for i ∈ 1:n
    x = b*x
end
y = exp( n * log( b ) )
println( "x = ", x, "; y = ", y )
x = 5.914; y = 7.227

Which result do you trust more and why?

Quiz 1: Exercise 3

True or false: there exists a continuous function \(f\) with a root in \([a,b]\) and \(f(a) f(b) > 0\)? Why or why not?

Quiz 1: Exercise 4

True or false: the function \(f(x) = x^2\) is a contraction on some interval \([a,b]\). Show your working.

Lecture 5

Exercise 5.1

Suppose \(g : [a,b] \to [a,b]\) is a contraction with constant \(L < 1\) and consider the simple iteration \(x_{n+1} = g(x_n)\). Let \(\xi \in [a,b]\) be the unique fixed point of \(g\) in \([a,b]\).

  1. Show that \(|x_1 - \xi| \leq \frac1{1-L} |x_1 - x_2|\),
  2. Hence, write down a lower bound on the number of iterations \(n\) to ensure \(|x_{n+1} - \xi|\leq \varepsilon\).

Exercise 5.2

Exercise 4.4 continued…

This is an example of Newton’s method!

\[\begin{align} x_{n+1} = \frac12 \left( x_n + \frac{a}{x_n} \right) \end{align}\]

is the Newton iteration with \(f(x) = x^2 - a\). Notice that \(\xi = \sqrt{a}\) and \(f'(\xi) = 2\sqrt{a}\), \(f''(\xi) = 2\).

Compute the order of convergence and asymptotic error constant numerically, and compare to Theorem 5.3.

Exercise 5.3

Assignment 5, Fall 2025, Section B

What happens when applying Newton to Kepler’s equation with \(\epsilon = 1\) (in this case \(f(2\pi) = f'(2\pi) = f''(2\pi) = 0\)).

Exercise 5.4

Suppose that \(g\) is twice continuously differentiable with \(g(\xi) = \xi\) and \(g'(\xi) = 0\).

  1. ✍️ Show that there exists \(\delta > 0\) such that \(x_{n+1} = g(x_n)\) converges to \(\xi\) for all \(x_1 \in [\xi - \delta, \xi + \delta]\).
  2. ✍️ Show that

\[\begin{align} \lim_{n\to\infty} \frac{|x_{n+1} - \xi|}{|x_n - \xi|^2} = \frac12 |g''(\xi)| \nonumber \end{align}\]

(whenever \(x_n \not= \xi\) for all \(n\)). What is the order of convergence when \(g''(\xi) \not= 0\)?

Exercise 5.5

Newton’s method \(x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}\) is the simple iteration with \(g(x) := x - \frac{f(x)}{f'(x)}\).

✍️ Suppose that \(f\) is three times continuously differentiable with \(f(\xi) = 0\) and \(f'(\xi) \not= 0\). Show that \(g'(\xi) = 0\) and \(g''(\xi) = \frac{f''(\xi)}{f'(\xi)}\). What does this tell you about Newton’s method?

Exercise 5.6

Fix \(a > 0\).

  1. ✍️ Show that Newton’s method applied to \(f(x) := \frac1x - a\) is given by \(x_{n+1} = x_n(2 - a x_n)\).
  2. ✍️ Define \(e_n := 1 - a x_n\) and show that \(e_{n+1} = e_n^2\). Hence, find all \(x_1\) for which \((x_n) \to \frac1a\).
  3. ✍️ Show that \(\left| x_{n+1} - \frac1a \right| = a \left| x_n - \frac1a \right|^2\). What are the order of convergence and the asymptotic error constant? Compare with the asymptotic error constant \(\mu = \frac12 \left| \frac{f''(\xi)}{f'(\xi)} \right|\) from lectures.
  4. πŸ’» Take \(a = 7\). Verify your answers to (ii) and (iii) numerically using \(x_1 = 0.1, 0.28\), and \(0.3\).

Problem Class 1

Exercise 1

Show that each of the following have fixed points on \([2,4]\):

\[\begin{align} g_1(x) &= 1 + x - \frac19 x^2 \nonumber\\ g_2(x) &= \pi + 0.99 \sin x \nonumber\\ g_3(x) &= x + 1 - \tan\frac{x}4 \end{align}\]

  1. Do you expect the simple iterations \(x_{n+1} = g_j( x_n )\) to converge?
  2. Why?
  3. Test your hypothesis numerically.
  4. Compute the order of convergence and asymptotic error constants.

Exercise 2

Suppose that \(g(\xi) = \xi\), \(g'(\xi) = 0\) and \(|g''|\) is bounded near \(\xi\).

  1. Show that the simple iteration \(x_{n+1} = g(x_n)\) with \(x_1 \approx \xi\) converges to \(\xi\).
  2. What is the order of convergence?
  3. Can you generalise this statement to the case where \(g'(\xi) = \cdots = g^{(\ell-1)}(\xi) = 0\) and \(g^{(\ell)}\) bounded near \(\xi\)?

Exercise 3

For \(\alpha \in (0,1]\), define \(x_{n+1} := x_n + \alpha ( g(x_n) - x_n )\) where \(g\) is continuous.

  1. Show that if \((x_n) \to \xi\) then \(\xi\) is a fixed point of \(g\)
  2. Suppose that \(g'\) is continuous with \(g'(\xi) < 0\). Show that there exists \(\alpha_0 > 0\) such that, if \(\alpha \leq \alpha_0\), then \((x_n)\) converges to \(\xi\) for all \(x_1\) sufficiently close to \(\xi\)

Lecture 6

Exercise 6.1

Show that the degree \(m_0\) Taylor polynomial of \(f\) about \(x_0\) solves (6.1) when \(X = \{ x_0 \}\).

Exercise 6.2

Write down the polynomial of least degree interpolating \(f(x) = \sin(x)\) at the points \(0, \frac{\pi}{2}, \pi\)

Exercise 6.3

Write down an error estimate for approximating \(f(x) = \sin(x)\) by \(I_{\{0, \frac\pi2, \pi\}}f(x) = - \frac4{\pi^2} x (x - \pi)\).

Exercise 6.4

Consider \(f(x) = e^{-x}\) on \([-1,1]\).

  1. Find a Lagrange interpolating polynomial \(p\) of \(f\) on \(\{ -1, 0 , 1\}\),

  2. Write down an error estimate for approximating \(f\) with \(p\) on \([-1,1]\).

Exercise 6.5

(\(\star\) more difficult)

Let \(X = \{x_0 < \cdots < x_n\}\) be \(n+1\) equispaced nodes on \([-1,1]\), i.e. \(x_j = -1 + jh\) with \(h = 2/n\), and let \(\ell_X(x) = (x-x_0)(x-x_1)\cdots(x-x_n)\) be the node polynomial.

  1. Fix \(x \in [x_k, x_{k+1}]\) for some \(0 \leq k \leq n-1\). By bounding \(|x - x_j|\) for \(j < k\) and \(j > k+1\) and using \(|x-x_k|\,|x-x_{k+1}| \leq h^2/4\), show that

    \[ |\ell_X(x)| \leq \frac{h^{n+1}}{4} (k+1)!\,(n-k)!, \]

    and deduce that \(\max_{x\in[-1,1]} |\ell_X(x)| \leq \dfrac{n!}{4} h^{n+1}\).

  2. Use Stirling’s formula, \(n! \sim \sqrt{2\pi n}\,(n/e)^n\), to show that there is a constant \(C > 0\), independent of \(n\), such that

    \[ \max_{x\in[-1,1]} |\ell_X(x)| \leq C\, \frac{(2/e)^n}{\sqrt n} \qquad \text{for all } n. \]

  3. By evaluating \(\ell_X\) at the point \(x^* = x_0 + h/2\), show that there is a constant \(c > 0\), independent of \(n\), such that

    \[ \max_{x\in[-1,1]} |\ell_X(x)| \geq c\, \frac{(2/e)^n}{n} \qquad \text{for all } n. \]

Note that \(2/e \approx 0.736\): parts 2 and 3 together show that \(\max\limits_{x\in[-1,1]} |\ell_X(x)|\) decays exponentially, but at a rate no better than \((2/e)^n\).

Exercise 6.6

(\(\star\) more difficult)

Fix \(\alpha > 0\) and let \(f(x) = \dfrac{1}{1+\alpha x^2}\), as in Example 6.2 (with \(\alpha=25\)).

  1. Using the geometric series \(f(x) = \sum_{k=0}^\infty (-\alpha)^k x^{2k}\) for \(|x| < 1/\sqrt\alpha\), show that

    \[\begin{align} f^{(2k)}(0) &= (2k)!\,(-\alpha)^k, \nonumber\\ f^{(2k+1)}(0) &= 0. \nonumber \end{align}\]

  2. Using partial fractions (the poles of \(f\) are at \(x = \pm i/\sqrt\alpha\)), show more generally that

    \[ \max_{x \in [-1,1]} |f^{(n)}(x)| = n!\, \alpha^{n/2}, \]

    with the maximum attained at \(x=0\).

  3. Combine part 2 with Exercise 6.5 and Theorem 6.2 to show that, for \(X\) the equispaced nodes on \([-1,1]\),

    \[ |f(x) - I_Xf(x)| \leq C\sqrt\alpha \, \frac{1}{\sqrt n} \left( \frac{2\sqrt\alpha}{e} \right)^n, \]

    and deduce that this bound converges to \(0\) whenever \(\alpha < \frac{e^2}{4} \approx 1.847\).

It turns out that we have convergence for all \(\alpha < \alpha_{\rm c} \approx 3.621\) Trefethen (2019), Epperson (1987).

Next week, we will see that for Chebyshev nodes, the node polynomial instead satisfies \(|\ell_X(x)| \leq 2^{1-n}\) and so

\[ |f(x) - I_Xf(x)| \leq 2\sqrt\alpha \left( \frac{\sqrt\alpha}{2} \right)^n, \]

which converges to \(0\) whenever \(\alpha < 4\). (A sharper argument, using that \(f\) is analytic throughout a neighbourhood of \([-1,1]\) in \(\mathbb C\) rather than just bounding derivatives along the real axis shows that Chebyshev interpolation converges for all \(\alpha > 0\).)

Lecture 7

Exercise 7.1

Show that \(T_0(x) = 1\) and \(T_1(x) = x\).

Exercise 7.2

Use \(\cos(x+y) = \cos x \cos y - \sin x \sin y\) to show that

  • \(T_{n+1}(x) = 2x T_{n}(x) - T_{n-1}(x)\) for \(n =1,2,\dots\),
  • Hence show that \(T_n\) is a polynomial of degree \(n\),
  • Show that the coefficent of \(x^n\) in \(T_n\) is \(2^{n-1}\) for \(n \geq 1\).

Exercise 7.3

Show that

  • \(\|T_n\|_{L^\infty([-1,1])} = 1\),
  • \(T_{n}\big( \cos\tfrac{j\pi}{n} \big) = (-1)^j\) for \(j = 0,\dots,n\) (extreme points; Chebyshev nodes of the second kind),
  • \(T_{n+1} = 0\) on \(\big\{ \cos \frac{(2j+1)\pi}{2(n+1)} \big\}_{j=0}^{n}\) (zeros; Chebyshev nodes of the first kind).

Exercise 7.4

Recall that \(T_{n+1}(x) = 2x T_n(x) - T_{n-1}(x)\) for \(n=1,2,...\).

  1. Use the recursion to write down \(T_2\), \(T_3\) and \(T_4\) in the monomial basis.
  2. Write down the Chebyshev nodes of the first kind \(X_{\mathrm I}\) for \(n = 2\) (i.e. the zeros of \(T_3\)) and check directly that \(\ell_{X_{\mathrm I}}(x) = t_3(x) = x^3 - \tfrac34 x\).
  3. Find \(\| \ell_{X_{\mathrm I}} \|_{L^\infty([-1,1])}\) for \(n=2\) by calculus, and compare with the equispaced nodes \(\{-1, 0, 1\}\).

Exercise 7.5

In the notes, we claimed that \(\ell_{X_{\mathrm{II}}}(x) = 2^{-n} \big( T_{n+1}(x) - T_{n-1}(x) \big)\) for \(n \geq 1\). Since \(\|T_n\|_{L^\infty} = 1\), this gives \(\| \ell_{X_{\rm II}} \|_{L^\infty} \leq 2^{1-n}\).

Prove the claim as follows:

  1. Show that \(T_{n+1}(\cos\theta) - T_{n-1}(\cos\theta) = -2 \sin\theta \sin n\theta\).
  2. Deduce that \(T_{n+1} - T_{n-1}\) vanishes on \(X_{\mathrm{II}} = \big\{ \cos\frac{j\pi}{n} \big\}_{j=0}^n\).
  3. Show that \(2^{-n} \big( T_{n+1} - T_{n-1} \big)\) is monic of degree \(n+1\), and conclude.

Exercise 7.6

Suppose we want to interpolate on a general interval \([a,b]\) rather than \([-1,1]\).

  1. Let \(\phi(t) = \frac{a+b}{2} + \frac{b-a}{2} t\), so that \(\phi\) maps \([-1,1]\) onto \([a,b]\). If \(Y = \{y_0,\dots,y_n\} \subset [-1,1]\) and \(X = \phi(Y) = \{\phi(y_0), \dots, \phi(y_n)\}\), show that \[ \ell_X\big(\phi(t)\big) = \left( \frac{b-a}{2} \right)^{n+1} \ell_Y(t). \]
  2. Deduce that, if \(X\) is the image of \(X_{\mathrm I}\) under \(\phi\), then \(\max_{x \in [a,b]} |\ell_X(x)| = 2 \left( \frac{b-a}{4} \right)^{n+1}\).
  3. Let \(f(x) = \sin x\) on \([0, \pi]\), interpolated at the image of \(X_{\mathrm I}\). Write down an error bound and find the smallest \(n\) that guarantees \(\max_{x\in[0,\pi]} |f(x) - I_Xf(x)| \leq 10^{-6}\).

Quiz 2

Quiz 2: Exercise 1

Recall that \(g : [a,b] \to \mathbb R\) is a contraction if there exists \(L < 1\) such that \(|g(x) - g(y)| \leq L |x-y|\) for all \(x,y \in [a,b]\).

Prove the uniqueness part of the contraction mapping theorem. That is, suppose that \(g :[a,b] \to [a,b]\) is a contraction with a fixed point \(\xi = g(\xi) \in [a,b]\) and show that \(\xi\) is the only fixed point of \(g\) in \([a,b]\).

Quiz 2: Exercise 2

Show that \(g(x) = \cos x\) maps \([0,\tfrac\pi3]\) to \([0,\tfrac\pi3]\) and is a contraction on \([0,\tfrac\pi3]\). What does this tell you about the iteration \(x_{n+1} = \cos x_n\) with \(x_1 = 0\)?

Quiz 2: Exercise 3

Recall that if \(f\) is \(n+1\) times continuously differentiable and \(X = \{x_0 < \dots < x_n\}\), then, for all \(x\), there exists \(\xi_x\) (between the smallest and largest of \(x, x_0, \dots, x_n\)) such that

\[\begin{align} f(x) - I_Xf(x) = \frac{f^{(n+1)}(\xi_x)}{(n+1)!} (x - x_0)(x-x_1) \cdots (x-x_n). \nonumber \end{align}\]

Let \(f(x) = x^3\) and \(X = \{ x_0 < x_1 < x_2 \} := \{-1, 0, 1\}\). Find a polynomial interpolant \(p\) of \(f\) on \(X\). Write down the interpolation error formula (above) in this case.

Quiz 2: Exercise 4

Let \(f(x) = \frac1x\) and \(X = \{1, 2\}\).

  1. Find the linear interpolant \(I_Xf\).
  2. Use the interpolation error formula to show that \(|f(x) - I_Xf(x)| \leq \frac14\) for all \(x \in [1,2]\). Hint: \(|(x-1)(x-2)|\) is largest on \([1,2]\) at \(x = \frac32\).
  3. Compute the actual error at \(x = \frac32\).

Lecture 8

Exercise 8.1

Let’s use the formula

\[ \begin{align} I_Xf(x) &= \sum_{j=0}^n f(x_j) \ell_j(x), \\ % \ell_j(x) &:= \prod_{k\not=j} \frac{x - x_k}{x_j - x_k} \nonumber \end{align} \]

to compute the polynomial interpolation of \(f(x) = \frac1{1+25x^2}\) (Runge function, as above):

Code
Runge = t -> 1/(1 + 25t^2)

function β„“β±Ό( j, t, x ) 
    if j == 0
        return prod( @. t - x[2:end] ) / prod( @. x[1] - x[2:end] )
    elseif j == length(x)-1 
        return prod( @. t - x[1:end-1] ) / prod( @. x[end] - x[1:end-1] )
    else
        return prod( @. t - x[1:j] ) * prod( @. t - x[(j+2):end] ) / ( prod( @. x[j+1] - x[1:j] ) * prod( @. x[j+1] - x[(j+2):end] ) )
    end
end 

function p_naive( t, x, y ) 
    r = 0
    for j in 0:(length(x)-1)
        r = r + β„“β±Ό(j, t, x) * y[j+1] 
    end
    return r
end 

egrid = range(-1, 1, length=401)

anim = @animate for n ∈ [10, 20, 50, 100, 200, 400, 600, 700, 760, 780:20:1020...]
    x = @. cos( Ο€*(0:n)/n )
    y = @. Runge( x )
    p = p_naive.( egrid, Ref(x), Ref(y) )
    err = @. max( abs( p - Runge(egrid) ), 1e-17 )

    plt1 = plot(Runge, -1, 1; label=L"y = f(x)", lw = 3, linestyle = :dash, 
            title = "Naive Lagrange formula: n = $n", ylims = (-0.5, 1.5))
    plot!(plt1, egrid, p; label=L"y = p(x)", lw = 3 )
    scatter!(plt1, x, y; primary = false, markersize = 2, markerstrokewidth = 0)

    plt2 = plot(egrid, err; yscale = :log10, ylims = (1e-17, 1e2), legend = false, lw = 2,
            title = @sprintf("max error = %.2e", maximum(err)))
    plot( plt1, plt2; size=(1000, 500) )
end

gif(anim, "../images/Naive Lagrange.gif", fps = 1, show_msg = false)

What is happening here?

Exercise 8.2

Suppose that \(X = \{ x_0 < ... < x_n \}\) and let \(\ell_j\) be the corresponding Lagrange polynomials. Show that \(\sum_{j=0}^n \ell_j(x) = 1\) for all \(x\).

Exercise 8.3

Explain why one may instead consider any weights of the form \(w_j := C \lambda_j\) in the Barycentric formula (8.3). Why might this be a good idea? See (8.4) for the weights appearing in the Barycentric formula for Chebyshev nodes of the second kind.

Exercise 8.4

Recall that the degree \(2\) polynomial interpolation of \(f(x) = \sin x\) on \(X = \{ x_0 < x_1 < x_2 \} = \{ 0, \frac\pi2, \pi \}\) is \(I_X f(x) = -\frac4{\pi^2} x(x-\pi)\). Write the Barycentric version of this formula (8.3).

Explain how you would have to update this formula if we added an extra point \(x_{3} = -2\pi\) to the interpolation set.

Exercise 8.5

Let \(n = 2\) and let \(X = X_{\mathrm{II}} = \big\{ \cos\frac{j\pi}{2} \big\}_{j=0}^2\) be the Chebyshev nodes of the second kind, so that \(x_0 = 1\), \(x_1 = 0\), and \(x_2 = -1\). Compute \(\lambda_0, \lambda_1, \lambda_2\) directly from the definition \(\lambda_j = \big( \prod_{k\not=j} (x_j - x_k) \big)^{-1}\) and check that they agree with (8.4).

Exercise 8.6

In the notes, we claimed that for the Chebyshev nodes \(X_{\mathrm{II}} = \big\{ x_j = \cos\frac{j\pi}{n} \big\}_{j=0}^n\) the barycentric weights \(\lambda_j := \big( \prod_{k\not=j} (x_j - x_k) \big)^{-1}\) are given by

\[ \lambda_j = \begin{cases} \frac{2^{n}}{4n} & \text{if } j = 0 \\ (-1)^j \frac{2^{n}}{2n} & \text{if } j = 1,\dots,n-1 \\ (-1)^n \frac{2^{n}}{4n} & \text{if } j = n \end{cases} \]

Prove the claim as follows:

  1. Show that \(\lambda_j = 1 / \ell_X'(x_j)\), where \(\ell_X(x) = \prod_{k=0}^n (x - x_k)\) is the node polynomial.
  2. Show that \(T_n'(\cos\theta) = n \frac{\sin n\theta}{\sin\theta}\). Using Exercise 7.5, deduce that \[ \ell_X(x) = \frac{2^{1-n}}{n} (x^2 - 1) T_n'(x). \]
  3. By differentiating \(T_n(\cos\theta) = \cos n\theta\) twice, show that \(T_n\) satisfies the Chebyshev differential equation \[ (1 - x^2) T_n''(x) - x T_n'(x) + n^2 T_n(x) = 0. \]
  4. Let \(w(x) := (x^2-1) T_n'(x)\). Show that \[ w'(x) = x T_n'(x) + n^2 T_n(x). \]
  5. Compute \(w'(x_j)\) for \(j = 0,\dots,n\) and conclude.
  6. Explain why we may replace \(\lambda_j\) by \((-1)^j\) (halved for \(j = 0, n\)) in the barycentric formula. Why is this a good idea when \(n\) is large?

Exercise 8.7

Let \(X = \{x_0 < \dots < x_n\}\) be the equispaced nodes on \([-1,1]\): \(x_j = -1 + jh\) for \(j = 0, \dots, n\), where \(h = \frac2n\).

  1. Show that \(\prod_{k\not= j} (x_j - x_k) = (-1)^{n-j} h^n \, j!\, (n-j)!\), and deduce that the barycentric weights are \[ \lambda_j = \frac{(-1)^{n-j}}{h^n\, n!} \binom{n}{j}. \]
  2. Using Exercise 8.3, explain why we may use the weights \(w_j := (-1)^j \binom{n}{j}\) in the Barycentric formula (8.3) instead. Compare the ratio \(\max_j |w_j| / \min_j |w_j|\) for these weights with the same ratio for the weights \((-1)^j \tau_j\) for Chebyshev nodes (\(\tau_j = \frac12\) for \(j = 0,n\) and \(\tau_j = 1\) otherwise) as \(n \to \infty\).
  3. Write a function EquispacedInterpolant(f, n), analogous to ChebyshevInterpolant from the notes, which returns the polynomial interpolant of f on the equispaced nodes (using the weights \(w_j\) from 2; in Julia, binomial(n, j) computes \(\binom{n}{j}\)). Compute the maximum error \(\max_{t} |f(t) - I_Xf(t)|\) over the grid range(-1, 1, length=2001) for:
    • the Runge function \(f(x) = \frac{1}{1 + 25x^2}\) with \(n = 10, 20, 40\),
    • \(f(x) = e^x\) with \(n = 10, 20, 40, 60\).
    Compare your results with the error estimate from Theorem 6.2 together with the bound \(\| \ell_X \|_{L^\infty([-1,1])} \leq \frac{e}{2\sqrt n} \big( \frac2e \big)^n\) for equispaced nodes from Lecture 6. Comment on what you see.

Lecture 9

Exercise 9.1

Let \(f(x) = e^x\) and \(X = \{\{0, 0, 1\}\}\) (so that \(z_0 = 0\) with \(m_0 = 2\), \(z_1 = 1\) with \(m_1 = 1\), and \(n = 2\)). Find the Hermite interpolant \(p \in \mathcal P_2\) of \(f\) on \(X\) by writing \(p(x) = a_0 + a_1 x + a_2 x^2\) and solving for the coefficients. Compare \(p\) with the Taylor polynomial of degree \(1\) about \(0\) and with the Lagrange interpolant of \(f\) on \(\{0, 1\}\).

Exercise 9.2

What is the least degree polynomial interpolant on \(X = \{\{x_0, x_0, \dots, x_0\}\}\) (where \(x_0\) is repeated \(n+1\) times)?

Exercise 9.3

Return to Exercise 9.1: compute the Hermite interpolant of \(f(x) = e^x\) on \(\{\{0, 0, 1\}\}\) again, this time using the divided difference table and Theorem 9.3.

Exercise 9.4

What is the Hermite interpolant of \(f(x) = \sin x\) on \(\{\{ 0,0,\pi, \pi\}\}\)? Hint: you can compute the divided difference tables in the same way as before.

Exercise 9.5

In this exercise, we prove Theorem 9.1. As in the notes, let \(z_0, \dots, z_k\) be distinct nodes with multiplicities \(m_0, \dots, m_k \geq 1\), and let \(n + 1 = \sum_{j=0}^k m_j\).

  1. Let \(r \in \mathcal P_n\) and suppose that \(r^{(l)}(z) = 0\) for \(l = 0, \dots, m-1\). Show that \(r(x) = (x - z)^m s(x)\) for some polynomial \(s\).
  2. Suppose that \(r \in \mathcal P_n\) satisfies \(r^{(l)}(z_j) = 0\) for all \(l = 0,\dots,m_j - 1\) and \(j = 0,\dots,k\). Show that \(r = 0\).
  3. Deduce that the Hermite interpolation problem has at most one solution in \(\mathcal P_n\).
  4. Consider the map \(L : \mathcal P_n \to \mathbb R^{n+1}\) defined by \(L p := \big( p^{(l)}(z_j) \big)_{j = 0,\dots,k, \; l = 0, \dots, m_j - 1}\). Show that \(L\) is linear and injective, and conclude that the Hermite interpolation problem has exactly one solution in \(\mathcal P_n\).

Exercise 9.6

In this exercise, we prove the error estimate for Hermite interpolation (compare with the Lagrange case in Lecture 6). We say that \(g\) has a zero of order \(m\) at \(z\) if \(g(z) = g'(z) = \dots = g^{(m-1)}(z) = 0\).

  1. (Rolle’s theorem with multiplicities) Suppose that \(g \in C^1([a,b])\) has zeros at distinct points \(w_1 < \dots < w_r\) in \([a,b]\) of orders \(k_1, \dots, k_r\), and let \(N := k_1 + \dots + k_r\). Show that \(g'\) has zeros in \([w_1, w_r]\) whose orders add up to at least \(N - 1\).
  2. Let \(f \in C^{n+1}([a,b])\), let \(X = \{\{x_0, \dots, x_n\}\} \subset [a,b]\) be a multiset, and let \(p \in \mathcal P_n\) be the Hermite interpolant of \(f\) on \(X\). Define the node polynomial \(\ell_X(x) := (x - x_0)(x - x_1) \cdots (x - x_n)\) (so repeated nodes give repeated factors). Show that, for every \(x \in [a,b]\), there exists \(\xi_x \in [\min (\{x\} \cup X), \max (\{x\} \cup X)]\) with \[ f(x) - p(x) = \frac{f^{(n+1)}(\xi_x)}{(n+1)!} \ell_X(x). \]

Exercise 9.7

Let \(X = \{\{0, 0, 1, 1\}\}\) and suppose that we know \(f(0) = y_0\), \(f'(0) = s_0\), \(f(1) = y_1\) and \(f'(1) = s_1\).

  1. Compute the divided difference table and show that the Hermite interpolant of \(f\) on \(X\) is \[ p(x) = y_0 + s_0 x + (d - s_0) x^2 + (s_0 + s_1 - 2d) \, x^2 (x - 1), \qquad \text{where } d := y_1 - y_0. \]
  2. Write down \(p\) for \(f(x) = e^x\) and compare it with Exercise 9.1.
  3. Use Exercise 9.6 to show that \(\max_{x \in [0,1]} |e^x - p(x)| \leq \frac{e}{384}\).
  4. More generally, suppose that \(p\) is the Hermite interpolant of \(f\) on \(\{\{a, a, b, b\}\}\). Show that \(\max_{x \in [a,b]} |f(x) - p(x)| \leq \frac{(b-a)^4}{384} \max_{[a,b]} |f^{(4)}|\). What does this tell you about approximating \(f\) on \([a,b]\) by a cubic Hermite interpolant on each of \(N\) subintervals of length \(h = \frac{b-a}{N}\)?

Exercise 9.8

  1. Let \(f \in C^n([a,b])\) and let \(X = \{\{x_0, \dots, x_n\}\} \subset [a,b]\) be a multiset. Show that there exists \(\xi \in [\min X, \max X]\) with \[ f[x_0, \dots, x_n] = \frac{f^{(n)}(\xi)}{n!}. \]
  2. Deduce that \(f[x_0, x_0 + h] \to f'(x_0)\) and, more generally, \(f[x_0, x_0 + h, \dots, x_0 + nh] \to \frac{f^{(n)}(x_0)}{n!}\) as \(h \to 0\). Explain why this makes the first case of Theorem 9.2 a natural definition.

Exercise 9.9

  1. Write a Julia function hermite_dd(x, df) which takes a vector of nodes x (sorted so that equal nodes are next to each other) and a function df(l, z) returning \(f^{(l)}(z)\), and returns the Newton coefficients \(f[x_0], f[x_0,x_1], \dots, f[x_0,\dots,x_n]\) using the divided difference table.
  2. Write a function newton_eval(c, x, t) which evaluates \(\sum_{k=0}^n c_k \pi_k(t)\) using \(O(n)\) operations.
  3. Check your code against Exercise 9.1, Exercise 9.4, and Exercise 9.7, and compute \(\max_{t \in [0,1]} |e^t - p(t)|\) for the cubic Hermite interpolant of \(e^x\) on \(\{\{0,0,1,1\}\}\).

Timer
00:00
min