[R] Coding matrix equation
jwiley.psych at gmail.com
Mon Apr 11 10:11:27 CEST 2011
Petr gave you one possibility. If you are looking for more matrix
?"%*%" # 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.
On Mon, Apr 11, 2011 at 12:43 AM, matthew.r.robinson at sheffield.ac.uk
<matthew.r.robinson at sheffield.ac.uk> wrote:
> Hi all,
> I have two matrices:
> G<-matrix(c(2.0, 0.5, 0.5, 0.5, 2.0, 0.5, 0.5, 0.5,2.0),3,3)
> P<-matrix(c(1.0, 0.5, 0.5, 0.5, 1.0, 0.5, 0.5, 0.5,1.0),3,3)
> and I want to run this equation to get a new matrix F:
> F = [P+2G]^-1/2 P [P+2G]^-1/2
> Could someone please tell me how to code this in R?
> Many thanks in advance for your time.
> Best wishes,
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Ph.D. Student, Health Psychology
University of California, Los Angeles
More information about the R-help