For a square matrix with an all-positive diagonal, elements are limited to 6 significant digits by rounding the diagonal and shrinking off diagonal elements toward zero. The off-diagonals are reduced by 3 percent as necessary until the determinant is positive.

posmat(x, ...)

Arguments

x

matrix with only positive diagonal elements

...

extra arguments, ignored

Author

Leonid Gibiansky, modified by Tim Bergsma

Examples

posmat(matrix(c(10.00006,20.00006,-30,40),2,2))
#>         [,1]     [,2]
#> [1,] 10.0001 -29.9999
#> [2,] 20.0000  40.0000

posmat(matrix(rep(100,4),2,2))
#>          [,1]     [,2]
#> [1,] 100.0000  96.9999
#> [2,]  96.9999 100.0000