Skip to main content

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

Suppose \(g \in C^1([a,b])\). 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\) unless \(y_n = \Omega\) for some \(n\) (for example, when \(y_1 = -\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

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

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 for \(n\) even

    \[ \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 \[ \begin{align} p(x) &= y_0 + s_0 x + (d - s_0) x^2 + (s_0 + s_1 - 2d) \, x^2 (x - 1) \end{align} \] 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 \(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\}\}\).

Lecture 10

Exercise 10.1

  1. Compute the divided difference table for \(f(x) = x^2\) on \(\{0, 1, 2\}\) and write down the Newton form of the interpolant. What do you notice?
  2. What are \(f[x_0, x_0]\) and \(f[x_0, x_0, x_0]\)?
  3. Why do we prefer the barycentric formula (8.3) to the naive Lagrange formula?
  4. What is the Hermite interpolant of \(f\) on \(\{\{a, a\}\}\)? How many conditions does the Hermite interpolant on \(\{\{0, 0, 1\}\}\) satisfy, and what is its degree?
  5. The next iterate of Newton’s method is the root of which interpolant of \(f\)? What about the secant method?

Exercise 10.2

Can you compute \(\int_0^1 e^{-x^2} \,\mathrm{d}x\) or \(\int_0^1 \frac{\sin x}{x} \,\mathrm{d}x\) exactly?

Exercise 10.3

Show that \(\int_0^{2\pi} \frac{1}{2\pi}(x + x \sin x) \,\mathrm{d}x = \pi - 1\).

Exercise 10.4

Write down the interpolation error formula for \(f - p\) when \(p\) interpolates \(f\) on \(n+1\) nodes (Theorem 6.2). What does it say when \(n = 0\) and \(X = \{a\}\)?

Exercise 10.5

Suppose \(f \in C^1([a,b])\). Show that

\[ \begin{align} \left| \int_{a}^b f - (b-a) f(a) \right| \leq \| f'\|_{L^\infty([a,b])} \frac{(b-a)^2}{2}. \end{align} \]

Exercise 10.6

Approximate \(\int_0^1 x \,\mathrm{d}x\) by the composite rectangular rule with \(n\) subintervals of equal length. What is the error?

Exercise 10.7

  1. Write down the polynomial \(p_1\) of degree at most \(1\) interpolating \(f\) on \(X = \{a, b\}\).
  2. Show that \(\int_a^b p_1(x) \,\mathrm{d}x = \frac{b-a}{2} \big( f(a) + f(b) \big)\).

Exercise 10.8

What is the sign of \((x-a)(x-b)\) on \([a,b]\)? Compute \(\int_a^b |(x-a)(x-b)| \,\mathrm{d}x\).

Exercise 10.9

The midpoint rule is \(\int_a^b f \approx (b-a) f\big(\tfrac{a+b}{2}\big)\).

  1. Show that the midpoint rule is exact for all polynomials of degree at most \(1\).
  2. Suppose \(f \in C^2([a,b])\). Show that \[ \left| \int_a^b f - (b-a) f\big(\tfrac{a+b}{2}\big) \right| \leq \frac{\|f''\|_{L^\infty([a,b])}}{24} (b-a)^3. \]
  3. Write down the composite midpoint rule on \(n\) subintervals of equal length and show that its error is bounded by \(\frac{\|f''\|_{L^\infty([a,b])}}{24} \frac{(b-a)^3}{n^2}\). Compare with Theorem 10.3.

Exercise 10.10

Let \(x_0, \dots, x_n \in [a,b]\) be distinct and let \(w_j = \int_a^b \ell_j\) be the weights in (10.2).

  1. Show that \(\{w_j\}\) are the unique weights for which \(\sum_{j=0}^n w_j f(x_j)\) is exact for all \(f \in \mathcal P_n\).
  2. Show that \(\sum_{j=0}^n w_j = b - a\).
  3. Let \(\hat x_j \in [0,1]\) and let \(\hat w_j\) be the corresponding weights on \([0,1]\). Show that the nodes \(x_j = a + (b-a) \hat x_j\) on \([a,b]\) have weights \(w_j = (b-a) \hat w_j\).
  4. Suppose the nodes are symmetric: \(x_{n-j} = a + b - x_j\) for all \(j\). Show that \(w_{n-j} = w_j\).

Quiz 3

Quiz 3: Exercise 1

Let \(f(x) = |x|\) and \(X = \{x_0, x_1, x_2\} = \{-1, 0, 1\}\). Find the polynomial interpolant \(I_Xf \in \mathcal P_2\) of \(f\) on \(X\) in (i) Lagrange form, (ii) Barycentric form, and (iii) Newton form.

Hints: For \(x \notin X\),

\[\begin{align} I_Xf(x) &= \sum_{j=0}^2 f(x_j)\, \ell_j(x) && \text{(Lagrange)} \nonumber\\ &= \left. \sum_{j=0}^2 \frac{\lambda_j f(x_j)}{x - x_j} \middle/ \sum_{j=0}^2 \frac{\lambda_j}{x - x_j} \right. && \text{(Barycentric)} \nonumber\\ &= f(x_0) + f[x_0, x_1]\,(x - x_0) + f[x_0, x_1, x_2]\,(x - x_0)(x - x_1) && \text{(Newton)} \nonumber \end{align}\]

where \(\ell_j(x) = \prod_{k \neq j} \frac{x - x_k}{x_j - x_k}\) are the Lagrange polynomials, \(\lambda_j = \frac{1}{\prod_{k\neq j}(x_j - x_k)}\) are the Barycentric weights, and \(f[x_j] = f(x_j)\), \(f[x_0, \dots, x_n] = \frac{f[x_1, \dots, x_n] - f[x_0, \dots, x_{n-1}]}{x_n - x_0}\) are the divided differences. You may use: \[ \ell_0(x) = \frac{x(x-1)}{2}, \quad \ell_2(x) = \frac{x(x+1)}{2}, \qquad \lambda_0 = \frac12, \quad \lambda_1 = -1, \quad \lambda_2 = \frac12, \qquad \begin{array}{c|ccc} x_j & f(x_j) & \text{1st} & \text{2nd} \\ \hline -1 & 1 & & \\ & & -1 & \\ 0 & 0 & & 1 \\ & & 1 & \\ 1 & 1 & & \end{array} \]

Quiz 3: Exercise 2

In this question, we prove that \(\cos\frac\pi8 = \frac{\sqrt{2 + \sqrt2}}{2}\). Recall that the Chebyshev polynomials satisfy \(T_n(\cos\theta) = \cos n\theta\).

  1. Show that \(T_m\big(T_n(x)\big) = T_{mn}(x)\) for all \(x \in [-1,1]\) and \(m, n \geq 0\).

We saw that \(T_4\big(\cos\frac\pi8\big) = \cos\frac\pi2 = 0\).
Moreover, by using (a) and \(T_2(x) = 2x^2 - 1\), we have \(T_4(x) = T_2\big(T_2(x)\big) = 8x^4 - 8x^2 + 1\).

  1. Show that the zeros of \(8x^4 - 8x^2 + 1\) are \(\pm\frac{\sqrt{2 \pm \sqrt2}}{2}\).
    Hint: let \(y = x^2\). You may use the fact that the solutions of \(8y^2 - 8y + 1 = 0\) are \(y = \frac{2 \pm \sqrt2}{4}\).
  2. The zeros of \(T_4\) are \(\cos\frac{(2j+1)\pi}{8}\) for \(j = 0, 1, 2, 3\). Explain why \(\cos\frac\pi8 = \frac{\sqrt{2 + \sqrt2}}{2}\).

Quiz 3: Exercise 3

  1. Write down the cubic polynomial \(p \in \mathcal P_3\) with \(p(0) = 1\), \(p'(0) = 0\), \(p(1) = 0\), and \(p'(1) = 0\).
    Hint: use the nodes \(X = \{\{0, 0, 1, 1\}\}\). You may use the template: \[ \begin{array}{c|cccc} x_j & f(x_j) & \text{1st} & \text{2nd} & \text{3rd} \\ \hline 0 & \underline{\qquad} & & & \\ & & \underline{\qquad} & & \\ 0 & \underline{\qquad} & & \underline{\qquad} & \\ & & \underline{\qquad} & & \underline{\qquad} \\ 1 & \underline{\qquad} & & \underline{\qquad} & \\ & & \underline{\qquad} & & \\ 1 & \underline{\qquad} & & & \end{array} \]
  2. Explain why \(q(x) = 1-p(x)\) satisfies \(q \in \mathcal P_3\) with \(q(0) = 0\), \(q'(0) = 0\), \(q(1) = 1\), \(q'(1) = 0\).

Lecture 11

Exercise 11.1

Suppose you know \(f(0)\), \(f(\tfrac12)\) and \(f(1)\). Find weights \(\hat w_0, \hat w_1, \hat w_2\) so that

\[\begin{align} \int_0^1 f(x) \mathrm{d}x % &\approx \hat w_0 f(0) + \hat w_1 f(\tfrac{1}2) + \hat w_2 f(1) \end{align}\]

is exact for \(f = 1\), \(x\) and \(x^2\).

Exercise 11.2

  1. What is the quadratic interpolant of \(f(x) = x^2\) on \(\{-1, 0, 1\}\)?
  2. What is the cubic interpolant \(p\) of \(f(x) = x^3\) on \(\{-1, 0, 1\}\)? Compare \(\int_{-1}^1 f\) and \(\int_{-1}^1 p\).
  3. Why is \(\int_a^b \big(x - \tfrac{a+b}{2}\big)^3 \,\mathrm{d}x = 0\)?

Exercise 11.3

  1. Compute the error of the trapezoid rule for \(f(x) = x^2\) on \([0,1]\) and compare it with the bound in Theorem 10.2.
  2. Compute the error of Simpson’s rule for \(f(x) = x^4\) on \([0,1]\) and compare it with the bound in Theorem 11.4.
  3. Explain why this shows that Simpson’s rule is not exact for all polynomials of degree \(4\).

Exercise 11.4

Let \(h = \frac{b-a}{3}\) and consider the Newton–Cotes rule with the four nodes \(a, a + h, a + 2h, b\).

  1. Show that the rule is \[ \int_a^b f \approx \frac{b-a}{8} \big[ f(a) + 3 f(a+h) + 3 f(a+2h) + f(b) \big]. \]
  2. Show that this rule is exact for all polynomials of degree at most \(3\), but not for \(x^4\).
  3. Compute the error of this rule for \(f(x) = x^4\) on \([0,1]\) and compare it with the error of Simpson’s rule from Exercise 11.3.

Exercise 11.5

Consider rules on \([0,1]\) of the form \(\int_0^1 f \approx w_0 f(0) + w_1 f(x_1)\) where \(w_0, w_1\) and \(x_1 \in (0,1]\) are free.

  1. Find \(w_0, w_1, x_1\) so that the rule is exact for all polynomials of degree at most \(2\).
  2. Show that the resulting rule is not exact for \(x^3\).
  3. Compare with the trapezoid rule (which also uses two nodes, one of which is \(0\)). What is the largest degree \(d\) for which you could hope to find a rule \(w_0 f(y_0) + w_1 f(y_1)\) (with both nodes free) that is exact on \(\mathcal P_d\)?

Exercise 11.6

In this exercise, we see why we use composite rules rather than Newton–Cotes rules with many nodes.

  1. Write a Julia function nc_weights(n) which returns the weights \(\hat w_0, \dots, \hat w_n\) of the Newton–Cotes rule on \([0,1]\) with nodes \(\hat x_j = \frac{j}{n}\). (You may solve the linear system obtained from exactness on \(1, x, \dots, x^n\), or integrate the Lagrange polynomials using Polynomials.jl.)
  2. For \(n = 1, \dots, 12\), print the weights. For which \(n\) do negative weights first appear? Plot \(\sum_j |\hat w_j|\) against \(n\).
  3. Suppose that the values \(f(x_j)\) are only known up to errors \(|\varepsilon_j| \leq \varepsilon\). Show that the computed quadrature differs from \(\sum_j w_j f(x_j)\) by at most \(\varepsilon \sum_j |w_j|\). Why is it desirable to have positive weights?
  4. Apply the Newton–Cotes rule with \(n + 1\) nodes on \([-1,1]\) to Runge’s function \(f(x) = \frac{1}{1 + 25x^2}\) (Example 6.2) for \(n = 2, 4, \dots, 20\) and plot the error (the exact integral is \(\frac25 \arctan 5\)). Compare with the composite Simpson rule using the same nodes.

Midterm (Fall 2025)

Midterm (Fall 2025): Question A1

Compulsory section, 2 pts. Suppose that a quantity \(x \not= 0\) is approximated by \(\widetilde{x}\). What is the relative error in this approximation?

Midterm (Fall 2025): Question A3

Compulsory section, 3 pts. How many floating point numbers are there in the interval \([1,2)\) with binary precision \(k = 3\)?

Midterm (Fall 2025): Question A4

Compulsory section, 3 pts. What is the relative condition number of the function \(f(x) = x - 1\)?

Midterm (Fall 2025): Question A5

Compulsory section, 3 pts. What scaling would you use in a graph to verify algebraic decay (i.e. \(O(n^{-\alpha})\) for some \(\alpha > 0\))?

(a). Linear scale, (b). Semi-logarithmic with the x-axis scaled, (c). Semi-logarithmic with the y-axis scaled, (d). Log-log plot (logarithmic scaling in both x- and y-axes).

Midterm (Fall 2025): Question A7

Compulsory section, 4 pts. Let \(f : [ 0, \tfrac\pi2 ] \to \mathbb R\) be given by \(f(x) = x^2\sin x - 1\). Show that there is a \(\xi \in [0,\tfrac\pi2]\) for which \(f(\xi) = 0\).

Midterm (Fall 2025): Question A8

Compulsory section, 2 pts. Here, we apply Newton’s method to \(f(x) = x^2\sin x - 1\) (from Question A7):

Newton iteration on f(x) = x^2 sin(x) - 1 with x1 = Ο€/2
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ iteration β”‚ sequence β”‚       residual β”‚       approximate Ξ± β”‚
β”‚         n β”‚     x[n] β”‚ r[n]=|f(x[n])| β”‚ log r[n]/log r[n-1] β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚       1.0 β”‚   1.5708 β”‚         1.4674 β”‚                 NaN β”‚
β”‚       2.0 β”‚  1.10371 β”‚      0.0876848 β”‚            -6.34694 β”‚
β”‚       3.0 β”‚  1.06891 β”‚     0.00165227 β”‚             2.63171 β”‚
β”‚       4.0 β”‚  1.06822 β”‚     6.52732e-7 β”‚             2.22338 β”‚
β”‚       5.0 β”‚  1.06822 β”‚    1.01918e-13 β”‚             2.10043 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why do we use the residuals \(r_n := |f(x_n)|\) instead of the errors \(|x_n - \xi|\) when we are approximating the order of convergence (\(\alpha\)) in this method?

Midterm (Fall 2025): Question A9

Compulsory section, 4 pts. Let \(g(x) := 1 + \frac{1}{x}\) and define \(x_1 = 1\) and \(x_{n+1} = g(x_n)\). Suppose that \((x_n) \to \xi\). What is the value of \(\xi\)?

Midterm (Fall 2025): Question A10

Compulsory section, 4 pts. Write down the Lagrange form of the polynomial of degree at most \(n\) interpolating \(f\) on \(X = \{ x_0, \dots, x_n \}\).

Midterm (Fall 2025): Question A11

Compulsory section, 4 pts. Consider the following finite difference table

\[\begin{align} x_0: \quad & f[x_0] = 0, \quad & f[x_0, x_1] = 1, \nonumber\\ x_1: \quad & f[x_1] = 0. \nonumber \end{align}\]

Which of the following statements are true? Select all that apply.

(a). The table does not correspond to any function \(f\), (b). The table determines a polynomial interpolant \(p\) of degree at least \(2\), (c). We must have \(f'(x_1) = 1\), (d). We must have \(x_0 = x_1\).

Midterm (Fall 2025): Question A12

Compulsory section, 5 pts. Write down the Trapezoid rule on \([-1,1]\) and show that it is exact for all polynomials of degree at most \(1\).

Midterm (Fall 2025): Question D

Optional section, 30 pts. Newton’s method for repeated roots.

  1. [2 points] Show that \(f(x) = e^x - x - 1\) satisfies \(f(0) = f'(0) = 0\) and \(f''(0) \not= 0\).
  2. [2 points] Here, we apply Newton’s method to \(f(x) = e^x - x - 1\). What is the order of convergence?
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ iteration β”‚    sequence β”‚         error β”‚       approximate Ξ± β”‚
β”‚         n β”‚        x[n] β”‚ e[n]=|x[n]-ΞΎ| β”‚ log e[n]/log e[n-1] β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚       1.0 β”‚         3.1 β”‚           3.1 β”‚                 NaN β”‚
β”‚       2.0 β”‚     2.24624 β”‚       2.24624 β”‚             0.71527 β”‚
β”‚       3.0 β”‚       1.512 β”‚         1.512 β”‚             0.51088 β”‚
β”‚       4.0 β”‚    0.939627 β”‚      0.939627 β”‚           -0.150621 β”‚
β”‚       5.0 β”‚    0.542328 β”‚      0.542328 β”‚               9.826 β”‚
β”‚       6.0 β”‚    0.295555 β”‚      0.295555 β”‚             1.99205 β”‚
β”‚       7.0 β”‚    0.155046 β”‚      0.155046 β”‚             1.52927 β”‚
β”‚       8.0 β”‚   0.0795256 β”‚     0.0795256 β”‚             1.35817 β”‚
    ...           ...             ...                 ...
β”‚      12.0 β”‚   0.0050958 β”‚     0.0050958 β”‚             1.15071 β”‚
β”‚      13.0 β”‚  0.00255006 β”‚    0.00255006 β”‚             1.13113 β”‚
β”‚      14.0 β”‚  0.00127557 β”‚    0.00127557 β”‚               1.116 β”‚
β”‚      15.0 β”‚ 0.000637923 β”‚   0.000637923 β”‚             1.10398 β”‚
β”‚      16.0 β”‚ 0.000318995 β”‚   0.000318995 β”‚              1.0942 β”‚
β”‚      17.0 β”‚ 0.000159506 β”‚   0.000159506 β”‚              1.0861 β”‚
β”‚      18.0 β”‚  7.97552e-5 β”‚    7.97552e-5 β”‚             1.07927 β”‚
β”‚      19.0 β”‚  3.98781e-5 β”‚    3.98781e-5 β”‚             1.07345 β”‚
β”‚      20.0 β”‚  1.99392e-5 β”‚    1.99392e-5 β”‚             1.06843 β”‚
β”‚      21.0 β”‚  9.96963e-6 β”‚    9.96963e-6 β”‚             1.06404 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Consider the modified Newton’s method

\[\begin{align*} x_{n+1} = x_n - 2 \frac{f(x_n)}{f'(x_n)}. \end{align*}\]

  1. [2 points] We apply this method to \(f(x) = e^x - x - 1\). Compare the table to that of the standard Newton method.
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ iteration β”‚    sequence β”‚         error β”‚       approximate Ξ± β”‚
β”‚         n β”‚        x[n] β”‚ e[n]=|x[n]-ΞΎ| β”‚ log e[n]/log e[n-1] β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚       1.0 β”‚         3.1 β”‚           3.1 β”‚                 NaN β”‚
β”‚       2.0 β”‚     1.39248 β”‚       1.39248 β”‚            0.292634 β”‚
β”‚       3.0 β”‚    0.313183 β”‚      0.313183 β”‚            -3.50653 β”‚
β”‚       4.0 β”‚   0.0163206 β”‚     0.0163206 β”‚             3.54474 β”‚
β”‚       5.0 β”‚  4.43937e-5 β”‚    4.43937e-5 β”‚             2.43539 β”‚
β”‚       6.0 β”‚ 3.27151e-10 β”‚   3.27151e-10 β”‚             2.17918 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Now suppose that \(f:[a,b]\to\mathbb R\) is four times continuously differentiable with root \(\xi \in (a,b)\) of multiplicity \(2\): that is, \(f(\xi) = f'(\xi) = 0\) and \(f''(\xi) \not= 0\). Further, we suppose that there exists \(A > 0\) such that

\[\begin{align*} \left| \frac{f'''(x) + f^{(4)}(x) (x - \xi)}{f''(y)} \right| \leq A \end{align*}\]

for all \(x,y \in [a,b]\). The aim of this section is to show that the modified Newton method converges at least quadratically to \(\xi\) for all \(x_1 \in [a,b]\) with \(|x_1 - \xi| \leq A^{-1}\). Notice that the modified Newton method can be written

\[\begin{align*} x_{n+1} - \xi &= \frac{ f'(x_n)(x_n - \xi) - 2 f(x_n) }{ f'(x_n) }. \end{align*}\]

  1. [8 points] By expanding the numerator \(g(x) := f'(x) (x - \xi) - 2 f(x)\) and denominator \(h(x) := f'(x)\), show that there exist \(\eta_n, \theta_n\) between \(x_n\) and \(\xi\) such that \[\begin{align*} x_{n+1} - \xi &= \frac {\frac1{3!} g'''(\eta_n) (x_n - \xi)^3} {h'(\theta_n) (x_n - \xi) } % = \frac16 \left[ \frac {f'''(\eta_n) + f^{(4)}(\eta_n) (\eta_n - \xi) } {f''(\theta_n)} \right] (x_n - \xi)^2. \end{align*}\]
  2. [4 points] Hence show that, if \(|x_1 - \xi| \leq A^{-1}\), then \(|x_{n+1} - \xi| \leq 6^{-n} |x_1 - \xi|\) and thus the modified Newton’s method converges.
  3. [4 points] Show that \((x_n)\) converges at least quadratically to \(\xi\).
  4. [4 points] What is the theoretical value of the asymptotic error constant when the modified Newton method is applied to \(f(x) = e^x - x - 1\)?
  5. [4 points] Show that the modified Newton method converges in \(1\) iteration for functions of the form \(f(x) = (x - \xi)^2\).

Midterm (Fall 2026)

Midterm (Fall 2026): Question A1

Compulsory section, 3 pts. Consider floating point numbers with binary precision \(k = 3\). What is the distance between consecutive floating point numbers in the interval \([4, 8)\)? What is the machine precision \(\epsilon_{\rm mach}\)?

Midterm (Fall 2026): Question A2

Compulsory section, 2 pts. True or false: in Float64 (binary precision \(k = 52\)), the computation \(1 + 2^{-60}\) returns exactly \(1\). Explain your answer.

Midterm (Fall 2026): Question A3

Compulsory section, 2 pts. What is the largest \(d\) such that the rectangular rule \(\int_a^b f \approx (b-a) f(a)\) is exact for all polynomials of degree at most \(d\)?

  1. \(d = 0\)
  2. \(d = 1\)
  3. \(d = 2\)
  4. \(d = 3\)

Midterm (Fall 2026): Question A4

Compulsory section, 7 pts. Approximate \(\int_{-1}^{+1} x^2 \, \mathrm{d}x = \frac23\) using (i) the rectangular rule, (ii) the trapezoid rule, and (iii) Simpson’s rule. Compare with the exact value.

Midterm (Fall 2026): Question A5

Compulsory section, 4 pts. Write down Newton’s method for computing \(\sqrt{2}\) (i.e. a root of \(f(x) = x^2 - 2\)). Compute \(x_2\) when \(x_1 = 1\).

Midterm (Fall 2026): Question A6

Compulsory section, 2 pts. The following table shows an iterative method for solving \(f(x) = x^2 - 2 = 0\) (here \(\xi = \sqrt{2}\)):

 n          x[n]      e[n]=|x[n]-ΞΎ|    log e[n]/log e[n-1]
------------------------------------------------------------
 1   1.000000000000   4.14214e-01
 2   2.000000000000   5.85786e-01         0.60678
 3   1.333333333333   8.08802e-02         4.70229
 4   1.400000000000   1.42136e-02         1.69142
 5   1.414634146341   4.20584e-04         1.82761
 6   1.414211438475   2.12390e-06         1.68028
 7   1.414213562057   3.15775e-10         1.67475
 8   1.414213562373   2.22045e-16         1.64764

Which of the following methods most likely produced this table?

  1. Relaxation
  2. Secant method
  3. Newton’s method

Midterm (Fall 2026): Question A7

Compulsory section, 4 pts. Let \(I_Xf \in \mathcal P_n\) be the polynomial interpolant of \(f : [-1,1] \to \mathbb R\) on \(n+1\) distinct nodes \(X\). Which of the following statements are true? Please select all that apply.

  1. \(I_Xf\) may have degree strictly less than \(n\)
  2. If \(f \in \mathcal P_n\), then \(I_Xf = f\)
  3. For the Chebyshev nodes \(X = \{\cos\frac{j\pi}{n}\}_{j=0}^n\), the barycentric weights alternate in sign
  4. For equispaced nodes, \(\max\limits_{x\in[-1,1]} |f(x) - I_Xf(x)| \to 0\) as \(n\to\infty\) for every continuous \(f\)

Midterm (Fall 2026): Question A8

Compulsory section, 5 pts. Find weights \(w_0, w_1\) such that the quadrature rule \(\int_0^1 f \approx w_0 f(0) + w_1 f(\tfrac13)\) is exact for all polynomials of degree at most \(1\). Is it exact for \(f(x) = x^2\)? (You may use \(\int_0^1 x^n \,\mathrm{d}x = \frac{1}{n+1}\) for \(n=0,1,2,...\).)

Midterm (Fall 2026): Question A9

Compulsory section, 2 pts. The following plots show the errors of two numerical methods, P and Q, as a function of the number \(n\) of function evaluations. The same data is shown on a log-log plot (left) and a semi-log plot (right).

  1. Is the decay of the error of method P algebraic or exponential?

  2. Is the decay of the error of method Q algebraic or exponential?

Midterm (Fall 2026): Question A10

Compulsory section, 5 pts. For \(b > 1\), the equation \(x^2 - 2bx + 1 = 0\) has roots

\[ \xi_\pm = b \pm \sqrt{b^2 - 1} = \frac{1}{b \mp \sqrt{b^2 - 1}}, \]

Here, we compute \(\xi_-\) in Float64 using both formulas:

       b         b - sqrt(b^2 - 1)        1 / (b + sqrt(b^2 - 1))
------------------------------------------------------------------
  b = 1e+04      5.000000055588316e-5      5.000000012500001e-5
  b = 1e+06       5.00003807246685e-7       5.00000000000125e-7
  b = 1e+08                       0.0                    5.0e-9

Which column do you trust? Explain why the formulas give different results.

Midterm (Fall 2026): Question A11

Compulsory section, 4 pts. Consider the following divided difference table: \[ \begin{array}{c|cc} \quad x_j \quad & \quad f(x_j) \quad & \quad f[x_0, x_1] \quad \\[4pt] \hline \quad x_0 \quad & \quad 1 \quad & \\[8pt] & & \quad -2 \quad \\[8pt] \quad x_1 \quad & \quad 1 \quad & \end{array} \] Which of the following statements are true? Please select all that apply.

  1. The table does not correspond to any function \(f\)
  2. We must have \(x_0 = x_1\)
  3. We must have \(f'(x_0) = 1\)
  4. The table determines a polynomial interpolant \(p\) of degree at most \(1\)

Midterm (Fall 2026): Question B

Optional section, 30 pts. Polynomial Interpolation. Let \(f(x) = 2^x\) and \(X = \{x_0, x_1, x_2\} = \{-1, 0, 1\}\).

  1. [14 points] Write down the polynomial interpolant \(I_Xf \in \mathcal P_2\) of \(f\) on \(X\) in both Lagrange and Newton form. Now add the node \(x_3 = 2\) and write down the polynomial \(p \in \mathcal P_3\) interpolating \(f\) on \(\{-1, 0, 1, 2\}\). Compare \(I_Xf(3)\) and \(p(3)\) with \(f(3)\).

  2. [5 points] Use the interpolation error formula \[ f(x) - I_Xf(x) = \frac{f^{(3)}(\xi_x)}{3!} (x + 1) x (x - 1) \] to show that \(|f(x) - I_Xf(x)| \leq \frac{2 (\log 2)^3}{3!} \cdot \frac{2}{3\sqrt3}\) for all \(x \in [-1,1]\). Hint: \(f^{(3)}(x) = (\log 2)^3 \, 2^x\), and \(|(x+1) x (x-1)| = |x^3 - x|\) is largest on \([-1,1]\) at \(x = \pm \frac{1}{\sqrt3}\).

  3. [5 points] Now let \(Y = \{y_0, y_1, y_2\}\) with \(y_0 = -\frac{\sqrt3}{2}, y_1 = 0, y_2 = \frac{\sqrt3}{2}\) (the zeros of the Chebyshev polynomial \(T_3(x) = 4x^3 - 3x\)). Show that \(\max\limits_{x \in [-1,1]} |(x - y_0)(x - y_1)(x - y_2)| = \frac14\). What is the corresponding error bound for \(|f(x) - I_Yf(x)|\)? Does \(X\) or \(Y\) give the better error bound?

  4. [6 points] The following semi-log plot shows the maximum error \(\max\limits_{x \in [-1,1]} |f(x) - I_Xf(x)|\) when interpolating \(f(x) = 2^x\) on \(n+1\) equispaced nodes and on \(n+1\) Chebyshev nodes \(\{\cos\frac{j\pi}{n}\}_{j=0}^n\) (computed with the barycentric formula in Float64).

    1. For small \(n\) (\(n \leq 10\)), is the decay of the error algebraic or exponential (or faster)?

    Next, we compare the time taken to evaluate \(I_Xf\) at \(1000\) points using two implementations: the naive implementation of the Lagrange form \(I_Xf(x) = \sum_j f(x_j) \prod_{k \neq j} \frac{x - x_k}{x_j - x_k}\), and the barycentric formula.

    1. Which of P and Q is the naive implementation? Explain why.

Midterm (Fall 2026): Question C

Optional section, 30 pts. Trapezoid Rule with End Point Derivatives. Suppose \(f\) is four times continuously differentiable. We will consider the following quadrature rule:

\[\begin{align*} \int_a^b f(x) \,\mathrm{d}x \approx \frac{b-a}{2} \big[ f(a) + f(b) \big] + \frac{(b-a)^2}{12} \big[ f'(a) - f'(b) \big]. \end{align*}\]

That is, we add a correction to the trapezoid rule which uses the derivative of \(f\) at both end points.

  1. [8 points] Show that this rule is exact for all polynomials of degree at most \(1\). Then show that it is exact for \(f(x) = (x - a)^2\) and \(f(x) = (x-a)^3\), and hence that it is exact for all polynomials of degree at most \(3\). (You may use \(\int_a^b (x-a)^n \,\mathrm{d}x = \frac{(b-a)^{n+1}}{n+1}\) for \(n=0,1,2,...\).)
  2. [3 points] Let \(p_3 \in \mathcal P_3\) be the Hermite interpolant of \(f\) on \(X = \{\{a, a, b, b\}\}\). Explain why \(\int_a^b p_3\) is equal to the quadrature rule applied to \(f\).
  3. [8 points] Recall that there exists \(\xi_x \in [a,b]\) such that \(f(x) - p_3(x) = \frac{f''''(\xi_x)}{4!} (x - a)^2 (x - b)^2\). Show that \[\begin{align*} \left| \int_a^b f(x)\,\mathrm{d}x - \frac{b-a}{2} \big[ f(a) + f(b) \big] - \frac{(b-a)^2}{12} \big[ f'(a) - f'(b) \big] \right| \leq \frac{\|f''''\|_{L^\infty([a,b])}}{720} (b-a)^5. \end{align*}\] Hint: \(\int_a^b (x-a)^2 (x-b)^2 \,\mathrm{d}x = \frac{(b-a)^5}{30}\).

Let \(x_j := a + j \frac{b-a}{n}\) for \(j = 0, \dots, n\) and note that \(\int_a^b f = \sum_{j=0}^{n-1} \int_{x_j}^{x_{j+1}} f\).

  1. [9 points] Apply the rule on each interval \([x_j, x_{j+1}]\) to show that the corresponding composite rule is \[\begin{align*} \int_a^b f \approx I_n' := \frac{b-a}{n} \Big[ \tfrac12 f(x_0) + \sum_{j=1}^{n-1} f(x_j) + \tfrac12 f(x_n) \Big] + \frac{1}{12}\left(\frac{b-a}{n}\right)^2 \big[ f'(a) - f'(b) \big]. \end{align*}\] Why do we only need the derivative of \(f\) at \(a\) and \(b\)? Use the error estimate from Question 3 to obtain an error estimate for \(I_n'\).

The following plot shows the errors in approximating \(\int_0^1 e^x \,\mathrm{d}x\) with the composite trapezoid rule \(I_n\) and the composite rule \(I_n'\) from Question 4, together with the curves \(C n^{-1}\), \(C n^{-2}\), \(C n^{-3}\) and \(C n^{-4}\):

  1. [2 points] What are the rates of convergence of \(I_n\) and \(I_n'\)?

Midterm (Fall 2026): Question D

Optional section, 30 pts. Simple Iteration. Define \(g(x) = 1 + \frac12 \sin x\) and \(I := [\frac12,\frac32]\).

  1. [3 points] Show that \(g(x) \in I\) for all \(x \in I\).
  2. [4 points] Show that \(g\) is a contraction on \(I\) with constant \(L = \frac12\).
  3. [4 points] Which theorem guarantees that \(g\) has a unique fixed point \(\xi \in I\) and that \(x_{n+1} = g(x_n)\) converges to \(\xi\) for all \(x_1 \in I\)? Explain why \(\xi \in [\frac12, \frac32]\).
  4. [5 points] Show that \(|x_{n+1} - \xi| \leq L^n |x_1 - \xi|\). Find \(n\) such that \(|x_{n+1} - \xi| \leq 10^{-3}\) is guaranteed for every \(x_1 \in I\). (You may use \(2^{10} = 1024\).)

Here, we apply the iteration with \(x_1 = 1\) and compare with \(x_N\) for \(N = 100\):

 n         x_n        r_n := |x_n - x_N|       r_{n+1} / r_n
------------------------------------------------------------
 1    1.000000000000      4.987e-01         0.1563
 2    1.420735492404      7.797e-02         0.0554
 3    1.494380992564      4.320e-03         0.0371
 4    1.498540884399      1.602e-04         0.0361
 5    1.498695355522      5.778e-06         0.0360
 6    1.498700925407      2.081e-07         0.0360
 7    1.498701126022      7.495e-09         0.0360
 8    1.498701133248      2.700e-10         0.0360

  1. [9 points] (a) Why do we plot \(|x_n - x_N|\) instead of the errors \(|x_n - \xi|\)?
  1. What do the plot and the table suggest about the order of convergence?
  2. The theory predicts that \(\frac{|x_{n+1} - \xi|}{|x_n - \xi|} \to \mu = |g'(\xi)| = \frac12 |\cos \xi|\). Estimate \(\mu\) and \(\xi\) from the table.
  1. [5 points] Show that \(\xi\) is a root of \(f(x) = 2x - 2 - \sin x\) and that \(x_{n+1} = g(x_n)\) is the relaxation method \(x_{n+1} = x_n - \lambda f(x_n)\) for some \(\lambda\). Which value of \(\lambda\) gives faster than linear convergence? Prove your answer.

Lecture 12

Exercise 12.1

By considering the change of variables \(y = \frac{2}{b-a} \left( x - \frac{a + b}{2} \right)\) and defining \(\tilde{f}(y) = \frac{b-a}{2} f\big( \tfrac{b-a}2 y + \tfrac{a+b}2 \big)\), show that

\[ \begin{align} \int_a^b f(x) \mathrm{d}x = \int_{-1}^1 \tilde{f}(y) \mathrm{d}y. \end{align} \]

Moreover, show that, if \(p\) is the polynomial interpolation of \(f\) on \(X \subset [a,b]\), then \(\tilde{p}\) is the polynomial interpolation of \(\tilde{f}\) on \(\tilde{X} \subset [-1,1]\) where \(\tilde{X} = \{ \frac{2}{b-a} \left( x - \frac{a + b}{2} \right) : x \in X \}\). As a result, we may without loss of generality consider the interval \([-1,1]\).

Exercise 12.2

Choose \(w_0, w_1\) and \(x_0, x_1\) such that

\[ \begin{align} \int_{-1}^1 f \approx w_0 f(x_0) + w_1 f(x_1) \end{align} \]

is exact for all polynomials of degree \(3 = 2n+1\).

Exercise 12.3

For \(n=1\), use the fact that Gauss quadrature is exact for all polynomials of degree \(2n+1 = 2(1) + 1 = 3\) to show that \[ \begin{align} \left| \int_{-1}^1 f(x) \mathrm{d}x - \left( f(-\tfrac{\sqrt3}{3}) + f(\tfrac{\sqrt3}{3}) \right) \right| % \leq \frac{1}{135} \max_{x\in [-1,1]} \big| f^{(4)}(x) \big|. \end{align} \]

Exercise 12.4

Approximate \(\log 2 = \int_1^2 \frac{1}{x} \mathrm{d}x\) using Gauss quadrature and evaluate an upper bound for the error.

Exercise 12.5

Compare this to the rectangular rule and its composite rule with 2 sub-intervals, and the trapezoid and Simpson rules.

Exercise 12.6

Show that \(P_0(x) = 1\), \(P_1(x) = x\), and \(P_2(x) = x^2 - \frac13\). What are the roots of \(P_2\) and compare to the nodes in Exercise 12.2.

Exercise 12.7

Show that the two definitions in Definition 12.2 are equivalent.

Exercise 12.8

Show that Gauss quadrature with nodes \(X = \{x_0, \dots, x_n\}\) is never exact for all polynomials of degree \(N > 2n+1\).

Exercise 12.9

  1. Write down the Gaussian quadrature rule with \(n=2\).
  2. What is the absolute error in approximating \(\log 2\) using the \(n=2\) scheme and following the same arguments as in class (see Exercise 12.4)?
  3. How would you prove an error bound for the \(n=2\) rule in general?

Exercise 12.10

Show that the roots of \(P_{n+1}\) are real, distinct, and lie in the open interval \((-1,1)\) (compare with the proof of Lemma 12.1).

Lecture 13

Exercise 13.1

  1. How would you write the following system of equations as a matrix equation?

\[ \begin{align*} 3x - y + z &= 1 \\ x-y-z &= 3\\ y + z &= 0 \end{align*} \]

  1. Why is there a solution to this equation?
  2. Use Cramer’s rule to compute the inverse of \(A\).
  3. Therefore show that \(x = 3, y = 4, z = -4\).

Exercise 13.2

What happens when you apply Gauss elimination to the following systems?

(i)

\[ \begin{align*} x - y + 2z &= -8 \\ 2x - 2y + 3z &= -20 \\ z &= 0 \end{align*} \]

(ii)

\[ \begin{align*} x - y + z &=4 \\ 2y - z &= -2 \\ 3x + 3y &= 6 \end{align*} \]

Exercise 13.3

Solve \(LU x = b\) where

\[ \begin{align*} L = \begin{pmatrix} 1 & & & \\ 3 & 1 & & \\ 4 & 2 & 1 & \\ 0 & 7 & 2 & 1 \end{pmatrix}, \qquad % U = \begin{pmatrix} 4 & 1& 0 & 0 \\ & 1 & 0 &1 \\ & & 1 & 0 \\ & & & 2 \end{pmatrix} , \qquad b = \begin{pmatrix} 1 \\ 1 \\ 1 \\ 1 \end{pmatrix} \end{align*} \]

Exercise 13.4

Show that forward substitution for solving \(Ly = b\) (where \(L \in \mathbb R^{n \times n}\) is lower triangular with non-zero diagonal entries) requires exactly \(n^2\) arithmetic operations (additions, subtractions, multiplications, and divisions). How many does backward substitution require?

Exercise 13.5

  1. Check that \(p(x) = \det(xI - C)\) in Example 13.3 when \(n = 2\).
  2. Use eigvals (from LinearAlgebra) to compute the roots of \(p(x) = x^3 - 6x^2 + 11x - 6\) and compare with roots from Polynomials.jl.

Lecture 14

Exercise 14.1

Use LU decomposition combined with forward and backwards substitution to solve the linear system of equations

\[ \begin{align} \begin{pmatrix} 2 & 3 & 4 \\ 4 & 5 & 10 \\ 4 & 8 & 2 \end{pmatrix} \begin{pmatrix} x\\y\\z \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \\ -1 \end{pmatrix}. \nonumber \end{align} \]

Exercise 14.2

Compute the \(LU\) decomposition of \[ \begin{align*} A = \begin{pmatrix} 1 & 2 & -3 \\ 0 & 1 & -1 \\ 1 & 1 & 0 \end{pmatrix} \end{align*} \] by hand, and check your answer with LU_decomp.

Exercise 14.3

What happens when you apply LU decomposition to the following matrix?

\[ \begin{align} A = \begin{pmatrix} 2 & 0 & 4 & 3 \\ -2 & 0 & 2 & -13 \\ 1 & 15 & 2 & -4.5 \\ -4 & 5 & -7 & -10 \end{pmatrix}. \nonumber \end{align} \]

Exercise 14.4

Use the PLU decomposition as above to solve

\[ \begin{align}\nonumber \begin{pmatrix} 1 & 0 & 2 \\ 0 & 2 & 1 \\ 2 & 0 & 3 \end{pmatrix} \begin{pmatrix} x\\y\\z\end{pmatrix} = \begin{pmatrix}0\\1\\-1\end{pmatrix}. \end{align} \]

Exercise 14.5

  1. Use the definitions directly to show that the following matrices are ill-conditioned for small \(\epsilon > 0\), \[ \begin{align}\nonumber \begin{pmatrix} 1 & 0 \\ -\epsilon^{-1} & 1 \end{pmatrix}, \qquad \begin{pmatrix} -\epsilon & 1 \\ 0 & \epsilon^{-1}-1 \end{pmatrix}, \end{align} \]
  2. Show that \(\|A\| = \max_{|x|=1} |Ax|\),
  3. Show that \(\|AB\| \leq \|A\|\|B\|\) and hence \(\|A^k\| \leq \|A\|^k\),
  4. What is \(\|D\|\) for diagonal \(D\)?
  5. A real matrix \(A\) is symmetric (i.e. \(A^T = A\)) if and only if there exists orthogonal \(P\) (i.e. \(P^{-1} = P^T\)) and diagonal \(\Lambda\) such that \(A = P\Lambda P^T\). Show that the columns of \(P\) are eigenvectors of \(A\),
  6. Show that, for symmetric matrices \(A\), the operator norm \(\|A\|\) is equal to \(\max_i |\lambda_i|\) where \((\lambda_i)\) are the eigenvalues of \(A\).

Exercise 14.6

Compute (by hand) the PLU decomposition of \[ \begin{align}\nonumber C = \begin{pmatrix} 0 & 6 & -10 \\ 15 & 0 & -6 \\ 5 & 1 & -4 \end{pmatrix} \end{align} \] using the largest pivot at each step, and check your answer with lu(C). Use your answer to compute \(\det C\).

Exercise 14.7

Let \(A\) be invertible.

  1. Show that \(\kappa(A) \geq 1\) and that \(\kappa(\alpha A) = \kappa(A)\) for all \(\alpha \not= 0\),
  2. Show that, if \(A\) is symmetric with eigenvalues \((\lambda_i)\), then \(\kappa(A) = \max_i |\lambda_i| / \min_i |\lambda_i|\),
  3. Compute \(\kappa(A)\) for \(A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}\) and check your answer with cond(A).

Lecture 15

Exercise 15.1

Let \(A\) and \(b\) be as in Example 15.1 and \(x = (\frac23, \frac23)^\top\). Compute the residual \(r := A x - b\), show that \(|r| = \frac{\sqrt3}{3}\), and check that \(r\) is orthogonal to both columns of \(A\) (i.e. \(A^\top r = 0\)).

Exercise 15.2

Fill in the details in Remark 15.1: for \(A \in \mathbb R^{m\times n}\) and \(b \in \mathbb R^m\), show that \(\frac{\partial}{\partial x_k} |Ax - b|^2 = 2\big(A^\top(Ax - b)\big)_k\).

Exercise 15.3

Suppose \(A \in \mathbb R^{m\times n}\) (\(m \geq n\)) has linearly independent columns and \(A = QR\) as above. Show that \(R\) is invertible and that \(A^\top Ax = A^\top b\) if and only if \(Rx = Q^\top b\).

Exercise 15.4

Use the normal equations to find the straight line \(p(t) = c_1 + c_2 t\) which best fits (in the least squares sense) the data \((0,1)\), \((1,3)\), \((2,4)\), \((3,4)\). Compute the residual and check that it is orthogonal to the columns of \(A\). Check your answer using A \ b in Julia.

Exercise 15.5

Let \(A \in \mathbb R^{m\times n}\). Show that \(A^\top A\) is invertible if and only if \(A\) has linearly independent columns. Deduce that, in this case, the least squares problem \(\min_{x} |Ax - b|\) has a unique solution.

Exercise 15.6

Let \(A \in \mathbb R^{n\times n}\) be invertible.

  1. Show that \(\|A^\top A\| = \|A\|^2\),
  2. Show that \(\|A^\top \| = \|A\|\),
  3. Deduce that \(\kappa(A^\top A) = \kappa(A)^2\) and check this numerically in Julia for a matrix of your choice (using cond).

Lecture 16

Exercise 16.1

Let \(A = \begin{pmatrix} a_1 | \cdots | a_n\end{pmatrix} \in \mathbb R^{m\times n}\), \(Q = \begin{pmatrix} q_1 | \cdots | q_n\end{pmatrix} \in \mathbb R^{m\times n}\) and let \(R \in \mathbb R^{n\times n}\) be upper triangular. Show that \(A = QR\) if and only if \[ \begin{align} a_j = \sum_{k=1}^j R_{kj} q_{k} \end{align} \] for all \(j = 1,...,n\).

Exercise 16.2

Let \(Q = \begin{pmatrix} q_1 | \cdots | q_n\end{pmatrix} \in \mathbb R^{m\times n}\). Show that \((Q^\top Q)_{ij} = q_i \cdot q_j\).

Exercise 16.3

Suppose that \(A = QR\) where \(Q \in \mathbb R^{m\times n}\) has orthonormal columns and \(R \in \mathbb R^{n\times n}\) is upper triangular. Show that \[ \begin{align} R_{ij} = q_i \cdot a_j \end{align} \] for all \(i\) and \(j\).

Exercise 16.4

Let \(Q \in \mathbb R^{n\times n}\) be orthogonal. Show that \(\kappa(Q) = 1\).

Exercise 16.5

Let \(v \in \mathbb R^m\) with \(|v| = 1\) and \(P := I - 2vv^\top\).

  1. Show that \(P\) is symmetric and orthogonal, and that \(P^2 = I\),
  2. Show that \(Pv = -v\) and that \(Pw = w\) for all \(w \in v^\perp\) (i.e. with \(v \cdot w = 0\)).

Exercise 16.6

Let \(a, z \in \mathbb R^m\) with \(|a| = |z|\) and \(a \not= z\), and let \(P := I - 2vv^\top\) with \(v := (a - z)/|a - z|\). Show that \(Pa = z\). Deduce that, for every \(a \not= 0\), there is a Householder reflection \(P\) with \(Pa = |a| e_1\) or \(Pa = -|a| e_1\).

Exercise 16.7

  1. Let \(\hat P \in \mathbb R^{(m-1)\times(m-1)}\) be orthogonal and \(P := \begin{pmatrix} 1 & 0 \\ 0 & \hat P \end{pmatrix}\). Show that \(P\) is orthogonal and that \[ \begin{align} P \begin{pmatrix} \alpha & b^\top \\ 0 & B \end{pmatrix} = \begin{pmatrix} \alpha & b^\top \\ 0 & \hat P B \end{pmatrix} \end{align} \] for all \(\alpha \in \mathbb R\), \(b \in \mathbb R^{n-1}\) and \(B \in \mathbb R^{(m-1)\times(n-1)}\),
  2. Show that, if \(P_1, \dots, P_n\) are orthogonal, then so is \(P_n \cdots P_1\),
  3. Deduce that the process described above gives \(Q^\top = P_n \cdots P_1\) orthogonal and \(R = Q^\top A\) upper triangular.

Exercise 16.8

Which sign should you choose in \(z = \pm|a| e_1\)?

Exercise 16.9

Suppose that \(Q\in \mathbb R^{m\times m}\) is orthogonal. Show that \(B = Q^\top A Q\) has the same eigenvalues as \(A\). Show that, if \(A\) is symmetric, then so is \(B\).

Exercise 16.10

Let \(A \in \mathbb R^{m\times n}\) and \(b \in \mathbb R^m\) be such that the columns of \(\begin{pmatrix} A \,|\, b\end{pmatrix} \in \mathbb R^{m\times(n+1)}\) are linearly independent, and suppose that Gram–Schmidt applied to \(\begin{pmatrix} A \,|\, b\end{pmatrix}\) gives \[ \begin{pmatrix} A \,|\, b\end{pmatrix} = \begin{pmatrix} Q \,|\, q_{n+1}\end{pmatrix} \begin{pmatrix} R & z \\ 0 & \rho \end{pmatrix} \] with \(Q \in \mathbb R^{m\times n}\), \(q_{n+1} \in \mathbb R^m\), \(R \in \mathbb R^{n\times n}\), \(z \in \mathbb R^n\) and \(\rho \in \mathbb R\).

  1. Show that \(A = QR\), \(z = Q^\top b\) and \(b = Qz + \rho q_{n+1}\),
  2. Deduce that the solution \(x\) of the least squares problem \(\min|Ax - b|\) solves \(Rx = z\), and that \(|Ax - b| = \rho\),
  3. Modified Gram–Schmidt is gram_schmidt with R[i, j] = Q[:, i]' * v in place of R[i, j] = Q[:, i]' * A[:, j] (that is, we remove the component along \(q_i\) from the updated vector \(v\) rather than from \(a_j\)). Write a function modified_gram_schmidt, apply it to [V b] with \(V\) and \(b\) as in Example 16.2 (\(d = 10\)) and solve \(Rx = z\) by backwards substitution. Compare the error \(|x - c_{\rm exact}|\) with the methods above. What do you notice?

Timer
00:00
min