Skip to content

Coding matrix equation

4 messages · Matthew Robinson, PIKAL Petr, Joshua Wiley +1 more

#
Hi

r-help-bounces at r-project.org napsal dne 11.04.2011 09:43:03:
Is this what you want?

(P+2*G)^-1/2 * P * (P+2*G)^-1/2

Regards
Petr
http://www.R-project.org/posting-guide.html
#
Hi Matt,

Petr gave you one possibility.  If you are looking for more matrix
operations see:

?"%*%" # the inner product of the matrices
?"%o%" # the outer product of the matrices
?"(" # for parentheses to help order things

require(MASS) # load the package MASS

?ginv # for the generalized inverse of a matrix

For things like constants which you just want treated normally, use
the regular multiplication operator, "*", not the matrix one.

HTH,

Josh

On Mon, Apr 11, 2011 at 12:43 AM, matthew.r.robinson at sheffield.ac.uk
<matthew.r.robinson at sheffield.ac.uk> wrote:

  
    
#
On Mon, Apr 11, 2011 at 08:43:03AM +0100, matthew.r.robinson at sheffield.ac.uk wrote:
Hi.

Try the following.

  sqrtSymMat <- function(A)
  {
      out <- eigen(A)
      D <- diag(out$values)
      U <- out$vectors
      U %*% sqrt(D) %*% t(U)
  }

  A <- sqrtSymMat(solve(P + 2*G))

  F <- A %*% P %*% A

See also the function svd() and its help ?svd.

The operator A^(1/2) works component-wise. There may be a function
computing the square root of a positive semidefinite matrix in some
of the CRAN extension packages

  http://cran.at.r-project.org/web/packages/index.html

but i am not sure. The package mvtnorm

  http://cran.at.r-project.org/web/packages/mvtnorm/index.html

computes the square root of a matrix internally. See the help
of the function ?rmvnorm.

Hope this helps.

Petr Savicky.