gpt4 book ai didi

matrix - GNU Octave 加载稀疏矩阵

转载 作者:行者123 更新时间:2023-12-04 07:46:16 24 4
gpt4 key购买 nike

我正在努力适应 Octave。
加载后 .mat包含稀疏矩阵的文件(您可以在此处获取它 https://sparse.tamu.edu [bcspwr01])我无法用它做任何事情。
尝试过类似 full 的命令, cell2mat等,但它会引发错误。
我想做的是使用 inv()det()在上面。
我如何实现这一目标?
非常感谢

最佳答案

mat 文件是一种用于存储一个或多个工作区变量的 Matlab 数据格式。您尝试打开的文件包含您想要的数据,但它不仅仅包含稀疏数据集。它是一种包含数据和许多其他元数据字段的结构。
保存后bcspwr01.mat文件,您可以使用以下命令将其加载到 Octave 工作区:

load bcspwr01.mat
如果您使用 Octave GUI,您将看到工作区现在列出了一个名为 Problem 的变量。类(class) struct .如果您只是使用命令行界面,则可以使用命令 whos 查看工作区变量列表。 . structure object包含许多可单独寻址以访问内容的命名字段。在这种情况下,它包含字段 title , A , name , id , date , author , ed , 和 kind .结构可以通过从命令行调用它来显示,如下所示:
>> 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
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 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

关于matrix - GNU Octave 加载稀疏矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67182628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com