[R] an easy way to construct this special matirx
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Aug 16 14:22:44 CEST 2007
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
More information about the R-help
mailing list