# Relative error and condition number using Hilbert matrices

I am getting confused by a question I am facing. It is about concluding that a high condition number matrix will lead to a high relative error. We are supposed to "prove" this by creating Hilbert matrices of size $$N$$ where $$N$$ is $$2,4,6,...,20$$.

The instructions are:

Create a Hilbert matrix $$A$$, set the exact solution as $$x = [1,...,1]^T$$ of size $$N$$, by setting $$b = Ax$$. Then solve $$Ax = b$$ by the backslash operator in Matlab (I am using Python now so I'll use lstsq(A,b) instead). Then make a list of the relative errors and compare it to the condition number of the matrices.

Now, for this example I use $$\operatorname{Hilbert}^{2x2}$$, which gives:

$$\begin{bmatrix} 1 & 1/2 \\ 1/2 & 1/3 & \end{bmatrix} \begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 3/2 \\ 5/6 \end{bmatrix}$$

A = hilbert(2)
x = np.ones(2)
b = A@x


So, now I have my $$A$$ and my $$b$$ and I am supposed to solve for $$x$$ and comparing this solution to the exact solution will give me my error. I use lstsq(A,b) and this gives:

$$\begin{bmatrix} 1 \\ 0.9999999999999992 \end{bmatrix}$$

I guess this is the "round-off error" which is mentioned in the lstsq documentation, but I fail to understand the rationale behind this. Where does this error come from, why does it fail to give the exact solution, and why does this error grow with the condition number?

I understand that the condition number is the relative stretching/shrinking and that it may produce large errors given errors in the input, but I fail to understand it in this context. Any help would be appreciated.

Thank you.

• Welcome to math.SE. To get the right font and spacing for text like "Hilbert" inside math formatting, use \text{Hilbert}. If you want it treated as an operator, use \operatorame{Hilbert}. Mar 5, 2023 at 20:26
• Thank you for that :) Mar 6, 2023 at 6:54
• Yes. Same task there. Mar 6, 2023 at 15:14