<< makematrix_hankel Makematrix makematrix_invhilbert >>

Makematrix >> Makematrix > makematrix_hilbert

makematrix_hilbert

Returns the hilbert matrix

Calling Sequence

A = makematrix_hilbert ( n )

Parameters

n :

a 1-by-1 matrix of doubles, integer value, the size of the matrix to return

A :

a n-by-n matrix of doubles, integer values

Description

Returns the hilbert matrix of size n

For i,j=1,2,...,n, we have: A(i,j) = 1 / (i + j - 1)

The Hilbert matrix is symetric, positive definite and ill conditioned.

cond(makematrix_hilbert ( n )) grows like exp(3.5*n).

Examples

A = makematrix_hilbert ( 5 )

// In the following example, we compute the conditionning of
// Hilbert's matrix for various values of n.
cond(makematrix_hilbert ( 2 ))
cond(makematrix_hilbert ( 4 ))
cond(makematrix_hilbert ( 6 ))
cond(makematrix_hilbert ( 8 ))
cond(makematrix_hilbert ( 10 ))

// In the following example, we compare
// the estimated condition number of Hilbert's
// matrix for increasing values of n with its theoretical value.
nv = 1:30;
for n = nv
c(n) = log(cond(makematrix_hilbert(n)));
e(n) = log(exp(3.5*n));
end
scf();
plot ( nv , c , "bo" );
plot ( nv , e , "r-" );
legend(["cond" "Theory"]);
xtitle("Conditionning of Hilbert matrix",...
"N","Condition Number");

// Analyse the condition number.
// Compare exact solution from the inverse Hilbert
// matrix with backslash operator.
// See how Scilab switches from Gaussian elimination
// with pivoting to a least squares solution.
err = zeros(14,1);
co = zeros(14,1);
for n = 2:15
A = makematrix_hilbert(n);
b = ones(n,1);
Ainv = makematrix_invhilbert(n);
x = A\b;
exact = Ainv*b;
err(n-1) = norm(x-exact)/norm(exact);
co(n-1) = cond(A);
end
h = scf();
plot(2:15,err,"r")
plot(2:15,co,"x");
h.children.log_flags="nln";
xtitle("Sensitivity of Hilbert matrix","n");
legend(["Relative error","Condition number"]);

Authors

Bibliography

http://en.wikipedia.org/wiki/Hilbert_matrix


Report an issue
<< makematrix_hankel Makematrix makematrix_invhilbert >>