Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Hilbert matrices Mata testing

From   "Feiveson, Alan H. (JSC-SK311)" <>
To   <>
Subject   RE: st: Hilbert matrices Mata testing
Date   Fri, 4 May 2007 10:19:49 -0500

As an aside - just because the determinant of a matrix is "low" doesn't
mean inverting it or solving a linear system with the matrix as
coefficients will give numerical problems. For example, if I_n is an n x
n identity matrix, the matrix a*I_n where a = 10^-10 (say) has a
determinant of 10^(-10*n). Yet there is clearly no problem in inverting
such a matrix. One way of normalizing is to look at the ratio of the
largest to smallest eigenvalue. In this example, the ratio is one (no
problem) - but for Hilbert matrices, the ratio becomes < < 1 very
quickly as the size of the matrix increases.

Al Feiveson

-----Original Message-----
[] On Behalf Of William
Gould, Stata
Sent: Friday, May 04, 2007 10:10 AM
Subject: Re: st: Hilbert matrices Mata testing

Marcos <> writes, 

> I found in the Mata manual Hilbert matrices. They are defined as a 
> matrix H with elements H[i,j]=1/(i+j-1). As it says in the help (type 
> help
> mf_hilbert):  Hilbert matrices are notoriously ill conditioned, with 
> near zero determinants.
> The help also adds Hilbert(n) and invHilbert(n) are used in testing 
> Mata.  I think that is intuitive as since they are ill matrices with 
> very low determinants and nearly singular you could use them to test 
> the quality of, for instance, Mata's solver (e.g., qrsolve, lusolve, 
> qrinv) and different inverters (e.g., cholinv, invsym).
> Am I right?  Could anybody supply an example of how Hilbert matrices 
> are used to test Mata?

We at StataCorp have do-files used for testing Stata.  One of the
do-files simply serves to call all othe others.  Currently, there are
3,103 do-files totalling 568,032 lines.

The part that tests Mata includes 325 files comprising 45,626 lines.
Here are a few lines from one of the files:

        assert(reldif(1/det(Hilbert(2)), 12)<1e-16)
        assert(reldif(1/det(Hilbert(3)), 2160)<1e-14)
        assert(reldif(1/det(Hilbert(4)), 6048000)<1e-13)
        assert(reldif(1/det(Hilbert(5)), 266716800000)<1e-12)
	assert(mreldif(pinv(pinv(Hilbert(4))), Hilbert(4))<1e-12))
	assert(mreldif(pinv(pinv(Hilbert(5))), Hilbert(5))<1e-11))

-- Bill
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index