How I make the below matrix | a^0 0 0 ... 0 | | a^1 a^0 0 ... 0 | | a^2 a^1 a^0 ... 0 | | . | | . | | . | | a^n a^(n-1) a^(n-2) ... a^0 | with no loops, where "a" is a constant? =======================================================================C?zar de Freitas Depto. de Estat?stica - UFPE Recife - Pernambuco - Brasil -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Cesar Augusto de Freitas Anselmo wrote:> > How I make the below matrix > > | a^0 0 0 ... 0 | > | a^1 a^0 0 ... 0 | > | a^2 a^1 a^0 ... 0 | > | . | > | . | > | . | > | a^n a^(n-1) a^(n-2) ... a^0 | > > with no loops, where "a" is a constant?What about ma <- matrix(rep(c(a^(0:n), 0), n+1), nrow=n+1, ncol=n+1) ma[upper.tri(ma)] <- 0 Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Try this:> n <- 3 > a <- 2 > out <- diag(n+1) > out[lower.tri(out)] <-a^apply(matrix(1:n,ncol=1),1,function(x)c(rep(0,x),1:(n-x+1)))[lower.tri(out)]> out[,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 2 1 0 0 [3,] 4 2 1 0 [4,] 8 4 2 1 R. Woodrow Setzer, Jr. Phone: (919) 541-0128 Experimental Toxicology Division Fax: (919) 541-5394 Pharmacokinetics Branch NHEERL MD-55; US EPA; RTP, NC 27711 |--------+-----------------------> | | cafa at cin.ufpe| | | .br | | | | | | 11/01/2000 | | | 09:41 AM | | | | |--------+-----------------------> >--------------------------------------------------------------------------| | | | To: r-help at stat.math.ethz.ch, cafa at cin.ufpe.br | | cc: | | Subject: [R] triangular matrix | >--------------------------------------------------------------------------| -------------- next part -------------- How I make the below matrix | a^0 0 0 ... 0 | | a^1 a^0 0 ... 0 | | a^2 a^1 a^0 ... 0 | | . | | . | | . | | a^n a^(n-1) a^(n-2) ... a^0 | with no loops, where "a" is a constant? =======================================================================C?zar de Freitas Depto. de Estat?stica - UFPE Recife - Pernambuco - Brasil -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Here's a way: tmpmat <- function(a,n) { x <- matrix(a,nrow=n,ncol=n) x <- x^pmax(0,row(x)-col(x)) x[row(x)<col(x)] <- 0 x } -- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._