Generate the Moler matrix of size n x n. The Moler matrix is for testing eigenvalue computations.

moler(n)

Arguments

n

integer

Details

The Moler matrix for testing eigenvalue computations is a symmetric matrix with exactly one small eigenvalue.

Value

matrix of size n x n

See also

Examples

(a <- moler(10))
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#>  [1,]    1   -1   -1   -1   -1   -1   -1   -1   -1    -1
#>  [2,]   -1    2    0    0    0    0    0    0    0     0
#>  [3,]   -1    0    3    1    1    1    1    1    1     1
#>  [4,]   -1    0    1    4    2    2    2    2    2     2
#>  [5,]   -1    0    1    2    5    3    3    3    3     3
#>  [6,]   -1    0    1    2    3    6    4    4    4     4
#>  [7,]   -1    0    1    2    3    4    7    5    5     5
#>  [8,]   -1    0    1    2    3    4    5    8    6     6
#>  [9,]   -1    0    1    2    3    4    5    6    9     7
#> [10,]   -1    0    1    2    3    4    5    6    7    10
min(eig(a))
#> [1] 8.582807e-06