GNU Octave 加载稀疏矩阵

GNU Octave load sparse matrix

我正在努力适应 Octave。

加载包含稀疏矩阵的 .mat 文件后(您可以在此处获取它 https://sparse.tamu.edu [bcspwr01])我无法对其执行任何操作。

尝试了 fullcell2mat 等命令,但它会抛出错误。

我想做的是在上面使用inv()det()

如何实现?

非常感谢

mat 文件是一种用于存储一个或多个工作区变量的 Matlab 数据格式。您尝试打开的文件包含您想要的数据,但它不仅仅包含稀疏数据集。它是一个包含数据和许多其他元数据字段的结构。

保存 bcspwr01.mat 文件后,您可以使用以下命令将其加载到 Octave 工作区:

load bcspwr01.mat

如果您使用的是 Octave GUI,您会看到工作区现在列出了一个名为 Problem 的 class struct 变量。如果您只是使用命令行界面,您可以使用命令 whos 查看工作区变量列表。 structure object 包含许多命名字段,可以单独寻址以访问内容。在这种情况下,它包含字段 titleAnameiddateauthoredkind。只需在命令行中调用即可显示该结构,如下所示:

>> 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 包含您的数据。将此作为变量访问,您可以通过键入以下内容进行操作:

>> Problem.A
ans =

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

此时您可以将其分配给另一个变量或直接使用它。

>> 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

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