GNU Octave load sparse matrix

Viewed 129

I'm trying to get used to Octave.

After loading a .mat file containing a sparse matrix (you can get it here https://sparse.tamu.edu [bcspwr01]) I'm not able to do anything with it.

Tryed commands like full, cell2mat, etc. but it throws errors.

What I want to do is use inv() or det() on it.

How do I achieve this?

Thanks a lot

1 Answers

A mat file is a Matlab data format for storing one or more workspace variables. The file you're trying to open contains the data you want, but it has more than just the sparse dataset. It is a structure that includes the data and a number of other meta-data fields.

After saving the bcspwr01.mat file, you can load it into the Octave workspace with the command:

load bcspwr01.mat

If you are using the Octave GUI, you will see the Workspace now lists a variable named Problem of class struct. If you are just using the command line interface, you can see a list of workspace variables with the command whos. A structure object contains a number of named fields that can be individually addressed to access the contents. In this case it contains the fields title, A, name, id, date, author, ed, and kind. The structure can be displayed just by calling it from the command line as follows:

>> Problem
Problem =

  scalar structure containing the fields:

    title = SYMMETRIC STRUCTURE (STANDARD TEST POWER SYSTEM - NEW ENGLAND)
    A =

Compressed Column Sparse (rows = 39, cols = 39, nnz = 131 [8.6%])

  (1, 1) -> 1
  (2, 1) -> 1
  (39, 1) -> 1
  (1, 2) -> 1
  (2, 2) -> 1
  (3, 2) -> 1
  (25, 2) -> 1
  (30, 2) -> 1
  (2, 3) -> 1
  (3, 3) -> 1
  (4, 3) -> 1
  (18, 3) -> 1
  (3, 4) -> 1
  (4, 4) -> 1
  (14, 4) -> 1
  (18, 4) -> 1
  (5, 5) -> 1
  (6, 5) -> 1
  (8, 5) -> 1
  (5, 6) -> 1
  (6, 6) -> 1
  (7, 6) -> 1
  (11, 6) -> 1
  (31, 6) -> 1
  (6, 7) -> 1
  (7, 7) -> 1
  (8, 7) -> 1
  (5, 8) -> 1
  (7, 8) -> 1
  (8, 8) -> 1
  (9, 8) -> 1
  (8, 9) -> 1
  (9, 9) -> 1
  (39, 9) -> 1
  (10, 10) -> 1
  (11, 10) -> 1
  (13, 10) -> 1
  (32, 10) -> 1
  (6, 11) -> 1
  (10, 11) -> 1
  (11, 11) -> 1
  (12, 11) -> 1
  (11, 12) -> 1
  (12, 12) -> 1
  (13, 12) -> 1
  (10, 13) -> 1
  (12, 13) -> 1
  (13, 13) -> 1
  (14, 13) -> 1
  (4, 14) -> 1
  (13, 14) -> 1
  (14, 14) -> 1
  (15, 14) -> 1
  (14, 15) -> 1
  (15, 15) -> 1
  (16, 15) -> 1
  (15, 16) -> 1
  (16, 16) -> 1
  (17, 16) -> 1
  (19, 16) -> 1
  (21, 16) -> 1
  (24, 16) -> 1
  (16, 17) -> 1
  (17, 17) -> 1
  (18, 17) -> 1
  (27, 17) -> 1
  (3, 18) -> 1
  (4, 18) -> 1
  (17, 18) -> 1
  (18, 18) -> 1
  (16, 19) -> 1
  (19, 19) -> 1
  (20, 19) -> 1
  (33, 19) -> 1
  (19, 20) -> 1
  (20, 20) -> 1
  (34, 20) -> 1
  (16, 21) -> 1
  (21, 21) -> 1
  (22, 21) -> 1
  (21, 22) -> 1
  (22, 22) -> 1
  (23, 22) -> 1
  (35, 22) -> 1
  (22, 23) -> 1
  (23, 23) -> 1
  (24, 23) -> 1
  (36, 23) -> 1
  (16, 24) -> 1
  (23, 24) -> 1
  (24, 24) -> 1
  (2, 25) -> 1
  (25, 25) -> 1
  (26, 25) -> 1
  (37, 25) -> 1
  (25, 26) -> 1
  (26, 26) -> 1
  (27, 26) -> 1
  (28, 26) -> 1
  (29, 26) -> 1
  (17, 27) -> 1
  (26, 27) -> 1
  (27, 27) -> 1
  (26, 28) -> 1
  (28, 28) -> 1
  (29, 28) -> 1
  (26, 29) -> 1
  (28, 29) -> 1
  (29, 29) -> 1
  (38, 29) -> 1
  (2, 30) -> 1
  (30, 30) -> 1
  (6, 31) -> 1
  (31, 31) -> 1
  (10, 32) -> 1
  (32, 32) -> 1
  (19, 33) -> 1
  (33, 33) -> 1
  (20, 34) -> 1
  (34, 34) -> 1
  (22, 35) -> 1
  (35, 35) -> 1
  (23, 36) -> 1
  (36, 36) -> 1
  (25, 37) -> 1
  (37, 37) -> 1
  (29, 38) -> 1
  (38, 38) -> 1
  (1, 39) -> 1
  (9, 39) -> 1
  (39, 39) -> 1

    name = HB/bcspwr01
    id = 13
    date = 1981
    author = B. Dembart, J. Lewis
    ed = I. Duff, R. Grimes, J. Lewis
    kind = power network problem

A contains your data. Access this as a variable you can manipulate by typing:

>> Problem.A
ans =

Compressed Column Sparse (rows = 39, cols = 39, nnz = 131 [8.6%])
                                                                                                
  (1, 1) -> 1
  (2, 1) -> 1
  ...

at this point you can assign it to another variable or work with it directly.

>> full(Problem.A)
ans =

 Columns 1 through 24:

   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
   0   0   1   1   0   0   0   0   0   0   0   0   0   1   0   0   0   1   0   0   0   0   0   0
   0   0   0   0   1   1   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   1   1   1   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   1   0   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   1   1   0   1   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   1   0   0   0   1   1   1   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   1   1   1   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   1   0   1   1   1   0   0   0   0   0   0   0   0   0   0
   0   0   0   1   0   0   0   0   0   0   0   0   1   1   1   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1   0   1   0   1   0   0   1
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1   0   0   0   0   0   0
   0   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   1   1   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   1   1   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   1   1
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   1   1
   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   1   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0
 Columns 25 through 39:

   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
   1   0   0   0   0   1   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1
   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
   1   1   0   0   0   0   0   0   0   0   0   0   1   0   0
   1   1   1   1   1   0   0   0   0   0   0   0   0   0   0
   0   1   1   0   0   0   0   0   0   0   0   0   0   0   0
   0   1   0   1   1   0   0   0   0   0   0   0   0   0   0
   0   1   0   1   1   0   0   0   0   0   0   0   0   1   0
   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0
   0   0   0   0   0   0   0   0   0   0   0   1   0   0   0
   1   0   0   0   0   0   0   0   0   0   0   0   1   0   0
   0   0   0   0   1   0   0   0   0   0   0   0   0   1   0
   0   0   0   0   0   0   0   0   0   0   0   0   0   0   1

or

>> ABC = Problem.A;
>> det(ABC)
ans = -12.000
Related