Problem sheet 1.

Please submit the question marked * to your tutor.

E1.1* (Catastrophic cancellation)

The following bit of code defines the polynomial $p(x) = ax^2 + bx +c$ and evaluates it at $x=2$

Complete the following to write a function to return the roots of a quadratic polynomial given coefficients a,b,c.

Try your code with $a = 10^{-3}$, $b=10^{6}$ and $c=10^{-3}$.

Does your function suffer from cancellation errors? If so, modify your function to avoid this.

By using the Taylor expansion for $\sqrt{1-x}$, work out what the actual roots are to 16 significant figures.

Note: Evaluate your polynomial at the computed roots, the value should be close to 0 (although not exactly 0 due to machine precision).

Hint: Which root would suffer from cancellation errors? If you know one root to high accuracy, can you work out the other?

E1.2 (Conditioning and the Hilbert matrix)

Run the following command. It defines the Hilbert matrix which has $(i,j)$ entry as $1/(i+j-1)$ for $i,j=1,\ldots, d$.

Let $b\in \mathbb{R}^d$ have random entries defined as follows.

We can solve the linear system $Ax = b$ and compute the residue $r = Ax - b$ as follow:

In the above, the norm computes $\|r\|:= \sqrt{r^\top r}$

Repeat the above for $d=10$ and $d=20$, what do you observe?