0

I generated a sparse matrix by:

A = full(gallery('tridiag',n,1,4,1));

When I try to generate the eigenvectors for this function via:

eig(A)

I receive the standard the error "Subscript indices must either be real positive integers or logicals." I read through Subscript indices must either be real positive integers or logicals, generic solution, but cannot figure out how to correct the problem. Is this simply due to the way I have created the sparse matrix, i.e. with the gallery command? If so, how can I create the matrix without this issue?

Error output

I was able to find the following:

They use different algorithms, tailored to different problems and different goals.

eig is a good, fast, general use eigenvalue/vector solver. It is appropriate for use when your matrix is of a realistic size that fits well in memory, and when you need all of the eigenvalues/vectors. Sparse matrices do not work at all in eig.

Eigs is a solver that is more appropriate for when you need only a limited subset of the eigenvalues/vectors. Here the matrix is often stored in sparse format, because as a full matrix, it would take up too much memory to store. It appears that eigs is based on ARPACK.

If you truly are asking for specifics on the actual algorithms, this is a question that is clearly inappropriate for this site. Sit down with a copy of "Matrix Computations", or better yet, read the pair of references listed in the doc for eigs. From What is the difference between 'eig' and 'eigs'?

Community
  • 1
  • 1
kathystehl
  • 831
  • 1
  • 9
  • 26
  • for n=100 those 2 lines of code work perfectly fine. – Ander Biguri Oct 28 '15 at 19:22
  • 1
    Can't reproduce your error. What is `n` in your code? – rayryeng Oct 28 '15 at 19:23
  • Maybe your n is not an integer? – Ander Biguri Oct 28 '15 at 19:23
  • I have only been using integers for my n value and I have tried n=100 before, and it still won't work. I'm at a complete loss. – kathystehl Oct 28 '15 at 19:37
  • I included a screenshot of the error in the question above. – kathystehl Oct 28 '15 at 19:37
  • No, I haven't. I'm not sure what that means, but I will look into it and update accordingly. – kathystehl Oct 28 '15 at 19:40
  • 1
    Something is odd with your installation or your workspace probably. First of all, you do not happen to have a `eig` function or variable you wrote yourself by accident right? (Just `clear' before doing that.) If that is not an issue, try to [regenerate your preferences](http://www.mathworks.com/matlabcentral/answers/99625-how-do-i-regenerate-my-matlab-preferences) and then [rehash your toolbox cache](http://www.mathworks.com/help/matlab/ref/rehash.html). – usεr11852 Oct 28 '15 at 19:52
  • The reported error message makes it really looks like `eig` is a variable... – usεr11852 Oct 28 '15 at 19:54
  • @usεr11852 thank you! I somehow accidently created a variable eig. I'm not sure how that happened, but it seemed to fix it. Sorry about that everyone, and thank you for all of your help. – kathystehl Oct 28 '15 at 19:57
  • Cool I am glad I could help, I formulated my comments into an answer so they read easier. – usεr11852 Oct 28 '15 at 20:03

1 Answers1

1

The reported error suggested that eig was treated as a variable. In that case one should clear the workspace (clear) and try eig again. That would also immediately evident if one used: which eig in which case MATLAB would return: eig is a variable. (Instead of a built-in method)

If that does not work the next obvious things are to use regenerate MATLAB's preferences and then rehash the toolbox cache in case any of the two has become corrupted from an external problem or by accident from the user.

usεr11852
  • 285
  • 10
  • 19