C ++ processing matrix operations: Preliminary use of Eigen Database

Source: Internet
Author: User

C ++ processing matrix operations: Preliminary use of Eigen Database
Preface:

Eigen is a library of linear arithmetic C ++ templates, including vectors, matrices, open source and Related algorithms. Powerful, fast, elegant, and supports multiple platforms. You can use this library to conveniently process matrix operations and achieve the same speed as matlab. It has now evolved to Eigen3, and the latest version is Eigen 3.1.2.

 

  Eigen preparation:

First, download the Eigen source code package on the Eigen official website. After the package is decompressed, it is directly placed in the directory where your usual software is located. You do not need to install the package. Eigen: http://eigen.tuxfamily.org/index.php? Title = Main_Page.

Then, when you need to use Eigen, add the header file directory where Eigen is located in the corresponding integrated development environment. For example, if I develop it in Qt, QtCreator is used, in the project file *. add the following code under pro:

INCLUDEPATH += C:\Qt\eigen 

For other development environments such as VS, refer to the references provided later in this article (the first one ).

 

  Some basic features of Eigen:

The matrix types in Eigen are generally represented by MatrixXXX. The data type can be determined based on the name. For example, 'D' indicates that double is not used to represent an integer ,; 'F' indicates float; 'I' indicates an integer; 'C' indicates complex, that is, a complex number; 'd indicates dynamic, that is, some dimensions in the matrix are uncertain, dynamic ...... For example, Matrix2cd represents a 2x2 dimension. Each element of Matrix2cd is a complex number. The real and virtual parts of a complex number are of the double type.

In Eigen, pay special attention to its data type. For example, if two vectors are multiplied to obtain a matrix, the element types in the vector must be the same as those in the Matrix. Otherwise, an error occurs.

 

The following is an example of simple use of the Eigen database. This example is very simple and involves a perceptual knowledge of Eigen usage. The experiment code is as follows:

# Include
 
  
# Include
  
   
# Include
   
    
Using namespace Eigen; using namespace std; int main () {Eigen: Vector2d v1, v2; // The variable v1 in Eigen <5, 6; // The default vector is the column vector cout <"v1 =" <endl <v1 <endl; v2 <4, 5; Matrix2d result = v1 * v2.transpose (); cout <"result:" <endl <result <endl ;}
   
  
 

 

  The experiment results are as follows:

  

 

  References:

C ++ matrix processing tool -- Eigen

Http://eigen.tuxfamily.org/index.php? Title = Main_Page

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.