matlab对稀疏矩阵求特征值,使用ARPACK查找稀疏矩阵的特征向量和特征值(称为PYTHON,MATLAB或FORTRAN子例程)...

几天前我问了一个如何找到大稀疏矩阵的特征值的问题 . 我没有答案,所以我决定描述一个潜在的解决方案 .

One question remains:

Can I use the python implementation of ARPACK

to compute the eigenvalues of a asymmetric sparse matrix.

首先,我想说,根本不需要使用FOTRAN驱动程序直接调用ARPACK的子程序 . 这很困难,我从来没有这样做过 . 但是可以做到以下几点:

选项1:Python

可以安装numpy和scipy并运行以下代码:

import numpy as np

from scipy.linalg import eigh

from scipy.sparse.linalg import eigsh

from scipy.sparse import *

from scipy import *

# coordinate format storage of the matrix

# rows

ii = array([0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4])

# cols.

jj = array([0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4])

# and the data

data=array([1.,-1.,-1., 2.,-2.,-2., 1., 1., 1., 1., 1.])

# now put this into sparse storage (CSR-format)

m=csr_matrix( (data,(ii,jj)), shape=(5,5) )

# you can check what you did

matrix([[ 1, -1, 0, 0, 0],

[-1, 2, -2, 0, 0],

[ 0, -2, 1, 1, 0],

[ 0, 0, 1, 1, 0],

[ 0, 0, 0, 0, 1]])

# the real part starts here

evals_large, evecs_large = eigsh(m, 4, which='LM')

# print the largest 4 eigenvalues

print evals_all

# and the values are

[-1.04948118 1. 1.48792836 3.90570354]

嗯,这一切都非常好,特别是因为它让我们很高兴阅读ARPACK的“写得很好”的手册 .

我有一个问题,我认为它不适用于非对称矩阵 . 至少将结果与matlab进行比较并不是很有说服力 .

选项2:MATLAB

% put your data in a file "matrix.dat"

% row col. data

% note that indexing starts at "1"

1 1 1.

1 2 -1.

......

load matrix.dat

M = spconvert(matrix)

[v,d] = eig(M)

% v - contains the eigenvectors

% d - contains the eigenvalues

我认为使用matlab更简单,适用于非对称矩阵 . 好吧,我有一个500000x500000稀疏矩阵,所以这是否适用于matlab ....是另一杯茶!我必须注意使用python我能够加载这个大小的矩阵并计算它的特征值而没有太多的麻烦 .

干杯,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值