# Thread: Plot condition number of Hilbert matrix against matrix size n.

1. ## Plot condition number of Hilbert matrix against matrix size n.

Plot condition number of Hilbert matrix against matrix size n. Propose set of linear equations with Hilbert matrix of coefficients and with solution .Try to solve the equation for different n and plot the norm of the residual against n.

Honestly I have no idea how to cooperate with it. I've just found out that i have to use hilb(n).

Plot condition number of Hilbert matrix against matrix size n. Propose set of linear equations with Hilbert matrix of coefficients and with solution .Try to solve the equation for different n and plot the norm of the residual against n.

Honestly I have no idea how to cooperate with it. I've just found out that i have to use hilb(n).
As:

$
H_n = \begin{bmatrix}
1 & \frac{1}{2} & ... & \frac{1}{n} \\
\frac{1}{2} & \frac{1}{3} & ... & \frac{1}{n+1} \\
: & : & \ddots & : \\
\frac{1}{n} & \frac{1}{n+1} & ... & \frac{1}{2n-1} \\
\end{bmatrix}
$

You want the solution of:

$
H_nx=c
$

to be:

$
x=\begin{bmatrix}1 \\ 1 \\ \vdots \\ 1 \end{bmatrix}
$

in which case we want:

$
c=\begin{bmatrix}\sum_{r=1}^n \frac{1}{r} \\ \\ \sum_{r=2}^{n+1} \frac{1}{r} \\ \\ \vdots \\ \\ \sum_{r=n}^{2n-1} \frac{1}{r}\end{bmatrix}
$

CB

3. Ummm.... It looks for me like a magic And how to write an m. file concerning solution of this problem? Would you be so kind and tell me?

4. Originally Posted by CaptainBlack
As:

$
H_n = \begin{bmatrix}
1 & \frac{1}{2} & ... & \frac{1}{n} \\
\frac{1}{2} & \frac{1}{3} & ... & \frac{1}{n+1} \\
: & : & \ddots & : \\
\frac{1}{n} & \frac{1}{n+1} & ... & \frac{1}{2n-1} \\
\end{bmatrix}
$

You want the solution of:

$
H_nx=c
$

to be:

$
x=\begin{bmatrix}1 \\ 1 \\ \vdots \\ 1 \end{bmatrix}
$

in which case we want:

$
c=\begin{bmatrix}\sum_{r=1}^n \frac{1}{r} \\ \\ \sum_{r=2}^{n+1} \frac{1}{r} \\ \\ \vdots \\ \\ \sum_{r=n}^{2n-1} \frac{1}{r}\end{bmatrix}
$

CB
Untested:

Code:
Hn=hilb(n);
x=ones(n,1);
c=(sum(Hn))';  % or Hn*x
x1=Hn\c;
err=sqrt((x1-x)'*(x1-x));
cn=cond(Hn);
CB