1.程序源码
#include <itpp/itbase.h>
using namespace itpp;
using std::cout;
using std::endl;
int main()
{
/*矩阵声明*/
mat A, Q, R;
/*使用字符串定义矩阵*/
A = "12,-51,4; 6,167,-68; -4,24,-41;";
/*A的QR分解结果*/
qr(A, Q, R);
/*打印结果*/
cout << "A = " << A << endl;
cout << "Q = " << Q << endl;
cout << "R = " << R << endl;
return 0;
}
2.编译源码
$ g++ -o example example.c -I/usr/local/include -L/usr/local/lib64 -litpp -lgfortran -lblas -llapack -lrefblas
3.运行结果
./example
A = [[12 -51 4]
[6 167 -68]
[-4 24 -41]]
Q = [[-0.857143 0.394286 0.331429]
[-0.428571 -0.902857 -0.0342857]
[0.285714 -0.171429 0.942857]]
R = [[-14 -21 14]
[0 -175 70]
[0 0 -35]]
网友评论