BrdGuest
Junior Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору #include <iosfwd> #include <sstream> #include <boost/numeric/ublas/matrix_expression.hpp> namespace boost { namespace numeric { namespace ublas { template<class E, class T, class ME> std::basic_ostream<E, T>& operator<<(std::basic_ostream<E, T>& os, const matrix_expression<ME>& m) { typedef typename ME::size_type size_type; size_type size1 = m().size1(); size_type size2 = m().size2(); std::basic_ostringstream< E, T, std::allocator<E> > s; s.flags(os.flags()); s.imbue(os.getloc()); s.precision(3); s.setf(std::ios_base::fixed, std::ios_base::floatfield); for (size_type i = 0; i < size1; ++i) { if (size2 > 0) { s << m()(i, 0); for (size_type j = 1; j < size2; ++j) { s << '\t' << m()(i, j); } } s << '\n'; } return os << s.str().c_str(); } } // namespace ublas } // namespace numeric } // namespace boost #include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/matrix_proxy.hpp> #include <cstdlib> #include <ctime> int main() { using namespace boost::numeric::ublas; using namespace std; const int N = 8; matrix<double> SourceMatrix(N, N); matrix<double> NumbersMatrix(N, 1); matrix<double> DestMatrix(N, N+1); srand(time(0)); // заполняем матрицы псевдослучайными числами от 0 до 100 for (unsigned i = 0; i < SourceMatrix.size1(); ++i) { for (unsigned j = 0; j < SourceMatrix.size2(); ++j) { SourceMatrix(i, j) = static_cast<double>(rand()) / RAND_MAX * 100; } NumbersMatrix(i, 0) = static_cast<double>(rand()) / RAND_MAX * 100; } cout << SourceMatrix << "\n" << NumbersMatrix << "\n"; project(DestMatrix, range(0, N), range(0, 5)) = project(SourceMatrix, range(0, N), range(0, 5)); project(DestMatrix, range(0, N), range(5, 6)) = NumbersMatrix; project(DestMatrix, range(0, N), range(6, N+1)) = project(SourceMatrix, range(0, N), range(5, N)); cout << DestMatrix; return 0; } |