Fwd: Re: [R] eigenvalues of a circulant matrix

Globe Trotter itsme_410 at yahoo.com
Tue May 3 15:15:39 CEST 2005


Thanks for looking into this! Sure, I will try and provide more info, but sorry
I seem to be doing really badly with posting....


> 
> Having cut&pasted from the data placed in the body of the
> message (omitted here) I get 216 numbers. Having put these
> in a vector x (in my own way):
> 
>   length(x)
>   ##[1] 216


> 
> Question 1:
> ===========
> Is this correct? Or has there been a problem with your
> posting of the data?

Yes, this is correct: it is supposed to be such that the circulant matrix is
symmetric and so Toeplitz. I am just ignoring the rest (which are pretty close
to x[107:1].


> 
> If it is correct, given that you seem to only use x[1:109],
> was there some point in giving the rest?

No, I should have deleted it -- sorry.

> Question 2:
> ===========
> Next, using your command:
> 
>   y<-x[c(109:1,0:108)]
> 
> I now get
> 
>   length(y)
>   ##[1] 217

My mistake: that should be 1 instead of 0. I sincerely apologize!
> 
> (as expected). The "0" in "0:108" seems to have been ignored
> (again as expected), so this is equivalent to
> 
>   y<-x[c(109:1,1:108)]
> 
> Is this as intended? If so, why use "0:108" instead of "1:108"?
> Check:
> 
>   y[1]    ##[1] 19.4495
>   x[109]  ##[1] 19.4495
> 
>   y[109]  ##[1] -0.00116801
>   x[1]    ##[1] -0.00116801
> 
>   y[110]  ##[1] -0.00116801
>   x[1]    ##[1] -0.00116801
> 
>   y[217]  ##[1] -6.28085
>   x[108]  ##[1] -6.28085
> 
> Can you confirm that this is as intended?
> 
> Comment 3:
> ==========
> You next command X=toeplitz(y): No apparent problems,
> it gives a symmetric result:
> 
>   which(X != t(X)) ## numeric(0)
> 
> with 217 rows and columns:
> 
>   dim(X)  ##[1] 217 217
> 
> and looks circulant:
> 
>   X[(1:5),(1:5)]
>             [,1]      [,2]      [,3]      [,4]      [,5]
>   [1,] 19.449500 -6.280850 -0.486405 -0.826079 -0.167792
>   [2,] -6.280850 19.449500 -6.280850 -0.486405 -0.826079
>   [3,] -0.486405 -6.280850 19.449500 -6.280850 -0.486405
>   [4,] -0.826079 -0.486405 -6.280850 19.449500 -6.280850
>   [5,] -0.167792 -0.826079 -0.486405 -6.280850 19.449500
> 
> Question 4:
> ===========
> Your next command, "eigen(X)", would simply output the results
> to screen and does not assign to anything.

true. But in my case, eigen(X)$vectors indicates the four columns to be NaN.

> Your next command "write(X,ncol=216,file="test.dat")" as it
> stands will write the toeplitz matrix X, constructed by
> your command "X<-toeplitz(y)" to file, but with 216
> columns instead of 217. However, the result consists
> simply of numbers, and there is nothing like "NA" or "NaN"
> in the file which I get.

I made a mistake in typing -- it is 1:108, instead of 0. The file test.dat
contains the symmetric circulant matrix on which I run the eigendecomposition
using  LAPACK.

> Nor are there any NAs or NaNs in X itself, of course.

No, there are none.

> 
> But, when you yourself did "write(X,ncol=216,file="test.dat")",
> perhaps the "X" in this command was different from the "X"
> which is the toeplitz matrix. So, was it the result of an
> assignment from "eigen(X)" and, if so, which component or
> components?

No, no, X was the Toeplitz matrix and all the confusion stems from my typo
(extremely sorry again!)

> Question/Comment 5:
> ===================
> So I have tried Z<-eigen(X). First of all, I get no problems
> with NAs or NaNs:
> 
>   which(is.na(Z$values))    ##numeric(0)
>   which(is.nan(Z$values))   ##numeric(0)
>   which(is.na(Z$vectors))   ##numeric(0)
>   which(is.nan(Z$vectors))  ##numeric(0)
> 
> Next, trying various options for wirting to file:
> 
>   write(Z,ncol=216,file="test.dat")
> 
> simply does not work (not a writable structure), while
> 
>   write(Z$values,ncol=216,file="test.dat")
> 
> produces simply a set of numbers, no NAs of NaNs, and likewise
> 
>   write(Z$vectors,ncol=216,file="test.dat")
> 
> (the only occurrences of non-numeric characters are "e", as
> in "e-05").
> 
> >> reports the following columns full of NaN's: 18, 58, 194, 200.
> >> (Note that eigen(X,symmetric=T) makes no difference and I get
> >> the same as above).
> 
> Question 6:
> ===========
> Was the file "test.dat" the result of your "write" command?
> Or was it left over from a previous activity, the "write"
> from this session having failed to execute for some reason?
> (In which case the NaNs would have nothing to do with the
> results of "eigen(X)").
> 
> 
> >> The second attachment contains only the eigenvectors
> >> obtained on calling a LAPACK routine directly (from C).
> >> The eigenvalues are essentially the same as that obtained
> >> using R. Here, I use the LAPACK-recommended double
> >> precision routine dspevd() routine for symmetric matrices
> >> in packed storage format.
> >> Note the absence of the NaN's....I would be happy to send
> >> my C programs to whoever is interested.
> 
> Well, I didn't get any NaNs in R either -- quite consistent
> with your C program!
> 
> Please clarify according to the questions above.
> 
> Best wishes,
> Ted.
> 

I am very sorry for all the errors and extra extra work that my typo caused
you.I should have been more careful. I apologize again!

Many thanks and best wishes!




More information about the R-help mailing list