简体   繁体   English

GNU Octave 加载稀疏矩阵

[英]GNU Octave load sparse matrix

I'm trying to get used to Octave.我正在努力适应 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.加载包含稀疏矩阵的.mat文件后(您可以在此处获取它https://sparse.tamu.edu [bcspwr01])我无法用它做任何事情。

Tryed commands like full , cell2mat , etc. but it throws errors.尝试了fullcell2mat等命令,但它会引发错误。

What I want to do is use inv() or det() on it.我想做的是在它上面使用inv()det()

How do I achieve this?我如何实现这一目标?

Thanks a lot非常感谢

A mat file is a Matlab data format for storing one or more workspace variables. mat 文件是一种 Matlab 数据格式,用于存储一个或多个工作区变量。 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:保存bcspwr01.mat文件后,您可以使用以下命令将其加载到 Octave 工作区:

load bcspwr01.mat

If you are using the Octave GUI, you will see the Workspace now lists a variable named Problem of class struct .如果您使用的是 Octave GUI,您将看到 Workspace 现在列出了一个名为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 .如果您只是使用命令行界面,您可以使用whos命令查看工作区变量列表。 A structure object contains a number of named fields that can be individually addressed to access the contents.结构 object包含许多命名字段,可以单独寻址以访问内容。 In this case it contains the fields title , A , name , id , date , author , ed , and kind .在本例中,它包含字段titleAnameiddateauthoredkind 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. A包含您的数据。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM