forceSymmetric {Matrix} | R Documentation

## Force a Matrix to 'symmetricMatrix' Without Symmetry Checks

### Description

Force `x` (inheriting from `Matrix` class) to `symmetricMatrix`, without a symmetry check (which is applied for all `as(x, "symmetricMatrix")` alikes).

### Usage

    forceSymmetric(x, uplo)

### Arguments

`x` | a (classed) square matrix.
`uplo` | optional string, `"U"` or `"L"`. The default is `"U"` unless `x` already has a `uplo` slot (i.e., when it is `symmetricMatrix`, or `triangularMatrix`), where the default will be `x@uplo`.

### Value

a square matrix inheriting from class `symmetricMatrix`.

### See Also

`symmpart` for the symmetric part, or the coercions `as(x, <symmetricMatrix class>)`.

### Examples

     ## Hilbert matrix
     i <- 1:6
     h6 <- 1/outer(i - 1L, i, "+")
     sd <- sqrt(diag(h6))
     hh <- t(h6/sd)/sd # theoretically symmetric
     isSymmetric(hh, tol=0) # FALSE; hence
     try( as(hh, "symmetricMatrix") ) # fails, but this works fine:
     H6 <- forceSymmetric(hh)

     ## result can be pretty surprising:
     (M <- Matrix(1:36, 6))
     forceSymmetric(M) # symmetric, hence very different in lower triangle
     (tm <- tril(M))
     forceSymmetric(tm)

[Package Matrix version 0.999375-33 Index]