[R] triangular matrix
Setzer.Woodrow@epamail.epa.gov
Setzer.Woodrow at epamail.epa.gov
Wed Nov 1 17:41:57 CET 2000
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list