smilingbuddha
smilingbuddha

Reputation: 14660

Weird behavior of a sparse Matrix under MATLAB

I have been given this 63521x63521 real sparse symmetric matrix in MATLAB and for some reason it seems to be behaving weirdly for some commands.

I am not sure if there is a 'defect' in the matrix file or in the way I am using MATLAB's commands.

Consider the following script. I have indicated the output of each of the steps.

  % Gives sparsity shown as expected, so this works fine
  spy(rYbus) 

  % I want the top 3 singular values of rYbus. But this line Returns empty matrix! Why/
  S = svds(rYbus,3);

     % Set exact answer and rhs and solve the linear system with iterative and direct method
     b_exact       = ones(size(Ybus,1),1); 
     rhs           = rYbus*b_exact      ;  


    % Following line gives Warning: Matrix is singular, close to singular or badly scaled.
    % Results may be inaccurate. RCOND = NaN. 
    % > In Ybustest at 14. 
     b_numerical_1 = rYbus\rhs;  

    % Even for a single GMRES iteration b_numerical_2 is a vector of Nans.  Why?                          
    b_numerical_2 = gmres(rYbus,rhs,[],[],1);  

Can anyone point out what may have gone wrong?

I have already used the "isnan" function to verify that the matrix rYbus does not have any nans. The size of the matrix is 63521 x 63521

Upvotes: 0

Views: 97

Answers (1)

fejikso
fejikso

Reputation: 130

Have you checked if your input sparse matrix rYbus has any NaNs? If I remember correctly, svds can give you an empty matrix instead of an error.

Another possible error is the size of rYbus. What is the size of it?

Upvotes: 1

Related Questions