itpp库PLU分解

2020-10-08  本文已影响0人  一路向后

1.程序源码

#include <itpp/itbase.h>

using namespace itpp;

using std::cout;
using std::endl;

int main()
{
        /*矩阵声明*/
        mat X, L, U;
        ivec p;

        /*使用字符串定义矩阵*/
        X = "9,6,0; 6,5,4; 3,4,10;";
        p = "1,1,1";

        /*X的PLU分解结果*/
        lu(X, L, U, p);

        /*打印结果*/
        cout << "X = " << X << endl;
        cout << "L = " << L << endl;
        cout << "U = " << U << endl;
        cout << "p = " << p << endl;

        return 0;
}

2.编译源码

$ g++ -o example example.c -I/usr/local/include -L/usr/local/lib64 -litpp -lgfortran -lblas -llapack -lrefblas

3.运行结果

./example
X = [[9 6 0]
 [6 5 4]
 [3 4 10]]
L = [[1 0 0]
 [0.333333 1 0]
 [0.666667 0.5 1]]
U = [[9 6 0]
 [0 2 10]
 [0 0 -1]]
p = [0 2 2]
上一篇 下一篇

猜你喜欢

热点阅读