[R] an easy way to construct this special matirx

Gabor Grothendieck ggrothendieck at gmail.com
Thu Aug 16 16:04:34 CEST 2007

```It was pointed out that the required matrix may not be square and
the superdiagonal was missing in my prior post.  Here is a revision:

r <- 2; nr <- 4; nc <- 5 # test data

x <- matrix(nr = nr, nc = nc)
x <- row(x) - col(x) + 1
(x >= 0) * r ^ x

On 8/16/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> Here are two solutions.  In the first lo has TRUE on the lower diagonal
> and diagonal. Then we compute the exponents, multiplying by lo to zero
> out the upper triangle.  In the second rn is a matrix of row numbers
> and rn >= t(rn) is the same as lo in the first solution.
>
> r <- 2; n <- 5 # test data
>
> lo <- lower.tri(diag(n), diag = TRUE)
> lo * r ^ (row(lo) - col(lo) + 1)
>
> Here is another one:
>
> rn <- row(diag(n))
> (rn >= t(rn)) * r ^ (rn - t(rn) + 1)
>
> On 8/15/07, shaowenhua at comcast.net <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
>

```