[R] an easy way to construct this special matirx

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Aug 16 10:37:31 CEST 2007


On 16-Aug-07 03:10:17, shaowenhua at comcast.net wrote:
> Hi,
> Sorry if this is a repost. I searched but found no results.
> I am wondering if it is an easy way to construct the following matrix:
> 
> r     1    0    0    0
> r^2   r    1    0    0
> r^3   r^2  r    1    0
> r^4   r^3  r^2  r    1
> 
> where r could be any number. Thanks.
> Wen

I dare say there's an even simpler way (and I feel certain
someone will post one ... ); but (example):

r<-0.1
r1<-r^((-3):0); r2<-r^(3:0)
R<-r1%*%t(r2)
R
##      [,1]  [,2]  [,3] [,4]
##[1,] 1.000 10.00 100.0 1000
##[2,] 0.100  1.00  10.0  100
##[3,] 0.010  0.10   1.0   10
##[4,] 0.001  0.01   0.1    1

R[upper.tri(R)]<-0
R
##      [,1] [,2] [,3] [,4]
##[1,] 1.000 0.00  0.0    0
##[2,] 0.100 1.00  0.0    0
##[3,] 0.010 0.10  1.0    0
##[4,] 0.001 0.01  0.1    1

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 16-Aug-07                                       Time: 09:37:28
------------------------------ XFMail ------------------------------



More information about the R-help mailing list