快速计算超大矩阵的eigenvalues的方法 java_Eigen密集矩阵求解 1 - 线性代数及矩阵分解...

简介

这里介绍线性系统的解析,如何进行各种分解计算,如LU,QR,SVD,特征值分解等。

简单线性求解

在一个线性系统,常如下表示,其中A,b分别是一个矩阵,需要求x:

A x   =   b Ax \:= \: bAx=b

在Eigen中,我们可以根据需要的精确性要求,性能要求,从而从好几种方法中选择一种来求解这个线性系统。

下面的示例,可以看到一种求解方法。

//matrxi_decomp1.cpp

#include

#include

using namespace std;

using namespace Eigen;

int main()

{

Matrix3f A;

Vector3f b;

A << 1,2,3, 4,5,6, 7,8,10;

b << 3, 3, 4;

cout << "Here is the matrix A:\n" << A << endl;

cout << "Here is the vector b:\n" << b << endl;

Vector3f x = A.colPivHouseholderQr().solve(b);

cout << "The solution is:\n" << x << endl;

}

执行:

$ g++ -I /usr/local/include/eigen3 matrxi_decomp1.cpp -o matrxi_decomp1

$

$ ./matrxi_decomp1

Here is the matrix A:

1 2 3

4 5 6

7 8 10

Here is the vector b:

3

3

4

The solution is:

-2

0.999997

1

这个示例中,使用矩阵的colPivHouseholderQr()方法,其返回一个ColPivHouseholderQR实例对象。因为调用对象是一个Matrix3f类型,所以也可以如此设计

ColPivHouseholderQR dec(A);

Vector3f x = dec.solve(b);

正如名字所示,这里ColPivHouseholderQR是一个采用列旋转方法的QR分解。下面Eigen提供的表列出了你可以使用分解类型:

Decomposition

Method

Requirements on the matrix

Speed(small-to-medium)

Speed(large)

Accuracy

PartialPivLU

partialPivLu()

Invertible(可逆)

++

++

+

FullPivLU

fullPivLu()

None

-

- -

+++

HouseholderQR

householderQr()

None

++

++

+

ColPivHouseholderQR

colPivHouseholderQr()

None

+

-

+++

FullPivHouseholderQR

fullPivHouseholderQr()

None

-

- -

+++

CompleteOrthogonalDecomposition

completeOrthogonalDecomposition()

None

+

-

+++

LLT

llt()

Positive definite(正定)

+++

+++

+

LDLT

ldlt()

Positive or negative semidefinite

+++

+

++

BDCSVD

bdcSvd()

None

-

-<

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值