1 #ifndef FAIF_GAUSS_ELIMINATOR 2 #define FAIF_GAUSS_ELIMINATOR 6 #if defined(_MSC_VER) && (_MSC_VER >= 1400) 8 #pragma warning(disable:4996) 12 #include <boost/numeric/ublas/vector.hpp> 13 #include <boost/numeric/ublas/matrix.hpp> 19 boost::numeric::ublas::vector<T> GaussEliminatorRef(boost::numeric::ublas::matrix<T>& m,
20 boost::numeric::ublas::vector<T>& y) {
24 int n =
static_cast<int>(y.size() );
27 for (
int i = 0; i < n; ++i) {
29 for (
int j = i + 1; j < n; ++j)
30 if( m(j,i) > m(max,i) )
33 for (
int j = 0; j < n; ++j)
34 std::swap( m(max,j), m(i,j) );
35 std::swap( y(max), y(i) );
37 for(
int k = i + 1; k < n; ++k)
38 y(k) -= m(k,i)/m(i,i) * y(i);
39 for (
int j = n-1; j >= i; --j)
40 for (
int k = i + 1; k < n; ++k)
41 m(k,j) -= m(k,i)/m(i,i) * m(i,j);
45 for (
int i = n - 1; i >= 0; --i) {
48 for (
int j = i - 1; j >= 0; --j) {
58 boost::numeric::ublas::vector<T> GaussEliminator(
const boost::numeric::ublas::matrix<T>& m,
59 const boost::numeric::ublas::vector<T>& y) {
60 typename boost::numeric::ublas::matrix<T> mm(m);
61 typename boost::numeric::ublas::vector<T> yy(y);
62 return GaussEliminatorRef(mm,yy);
68 #endif //FAIF_GAUSS_ELIMINATOR