CGAL中数值求解示例—OpenNL
转载自:http://blog.csdn.net/jingwenlai_scut/article/details/2111087
在CGAL中,对线性方程组的求解默认是使用OpenNL,当然也可以结合Taucs库进行求解。本文记录的是利用OpenNL进行数值求解的例子。OpenNL的整个库的源代码
可以在$(CGALROOT)/OpenNL/中找到。下面的程序举例了如何使用OpenNL求解IX=[3 4]^T.
Source code:
#include <CGAL/basic.h>
#include <CGAL/OpenNL/linear_solver.h>
using namespaceCGAL;
#include <iostream>
using namespacestd;
typedef OpenNL::DefaultLinearSolverTraits<float>SparseLA;
typedef SparseLA::Vector Vector;
typedef SparseLA::Matrix Matrix;
int main()
{
Matrix A(2,2);
Vector X(2);
Vector B(2);
A.set_coef(0,0,1);
A.set_coef(0,1,0);
A.set_coef(1,0,0);
A.set_coef(1,1,1);
B[0] = 3, B[1] = 4;
X[0] = X[1] = 0;
float d;
SparseLA m_linearAlgebra;
m_linearAlgebra.linear_solver(A,B,X,d);
cout<<"The result is : "<<endl;
cout<<X[0]<<" "<<X[1]<<endl;
return 0;
}