include iostream include EigenDense using namespace Eigen int

  • Slides: 10
Download presentation

Пример программы: #include <iostream> #include <Eigen/Dense> using namespace Eigen; int main() { Matrix. Xd

Пример программы: #include <iostream> #include <Eigen/Dense> using namespace Eigen; int main() { Matrix. Xd m(2, 2); m(0, 0) = 3; m(1, 0) = 2. 5; m(0, 1) = -1; m(1, 1) = m(1, 0) + m(0, 1); std: : cout << "Here is the matrix m: n" << m << std: : endl; }

Библиотека Eigen позволяет складывать, вычитать, умножать и делить матрицы и векторы, а также позволяет

Библиотека Eigen позволяет складывать, вычитать, умножать и делить матрицы и векторы, а также позволяет транспонировать матрицы и находить сопряженную матрицу. #include <iostream> #include <Eigen/Dense> using namespace Eigen; int main() { Matrix 2 d mat; mat << 1, 2, 3, 4; Vector 2 d u(-1, 1), v(2, 0); std: : cout << "Here is mat*mat: n" << mat*mat << std: : endl; std: : cout << "Here is mat*u: n" << mat*u << std: : endl; std: : cout << "Here is u^T*mat: n" << u. transpose()*mat << std: : endl; std: : cout << "Here is u^T*v: n" << u. transpose()*v << std: : endl; std: : cout << "Here is u*v^T: n" << u*v. transpose() << std: : endl; std: : cout << "Let's multiply mat by itself" << std: : endl; mat = mat*mat; std: : cout << "Now mat is mat: n" << mat << std: : endl; }

Array – класс множеств. Он обладает теми же параметрами, что и класс матриц, однако

Array – класс множеств. Он обладает теми же параметрами, что и класс матриц, однако позволяет совершать операции с неалгебраическими значениями и имеет ряд дополнительных свойств. #include <Eigen/Dense> #include <iostream> using namespace Eigen; using namespace std; int main() { Array. XXf m(2, 2); // assign some values coefficient by coefficient m(0, 0) = 1. 0; m(0, 1) = 2. 0; m(1, 0) = 3. 0; m(1, 1) = m(0, 1) + m(1, 0); // print values to standard output cout << m << endl; // using the comma-initializer is also allowed m << 1. 0, 2. 0, 3. 0, 4. 0; // print values to standard output cout << m << endl; }

Пример программы: #include <Eigen/Dense> #include <iostream> using namespace Eigen; using namespace std; int main()

Пример программы: #include <Eigen/Dense> #include <iostream> using namespace Eigen; using namespace std; int main() { Array. Xf a = Array. Xf: : Random(5); a *= 2; cout << "a =" << endl << a << endl; cout << "a. abs() =" << endl << a. abs() << endl; cout << "a. abs(). sqrt() =" << endl << a. abs(). sqrt() << endl; cout << "a. min(a. abs(). sqrt()) =" << endl << a. min(a. abs(). sqrt()) << endl; }

Перевод из array в matrix: #include <Eigen/Dense> #include <iostream> using namespace Eigen; using namespace

Перевод из array в matrix: #include <Eigen/Dense> #include <iostream> using namespace Eigen; using namespace std; int main() { Matrix. Xf m(2, 2); Matrix. Xf n(2, 2); Matrix. Xf result(2, 2); m << 1, 2, 3, 4; n << 5, 6, 7, 8; result = (m. array() + 4). matrix() * m; cout << "-- Combination 1: --" << endl << result << endl; result = (m. array() * n. array()). matrix() * m; cout << "-- Combination 2: --" << endl << result << endl; }