C + + processing matrix operations: Eigen Library Preliminary Learning use

Source: Internet
Author: User

Preface:

Eigen is a C + + Template library for linear arithmetic, including: vectors, matrices, open source, and related algorithms. Powerful, fast, elegant and multi-platform support, you can use this library to facilitate the operation of some matrix, similar to MATLAB as fast. has now developed to Eigen3, the latest version of the current Eigen 3.1.2.

  Eigen Use preparatory work:

First to eigen official online download Eigen source package, download after the decompression directly put to their usual software in the directory, do not need to install. Eigen is: Http://eigen.tuxfamily.org/index.php?title=Main_Page.

Then when you need to use to Eigen, in the corresponding integrated development environment to add Eigen in the header file directory can, for example, I developed under QT, using the qtcreator, you need to add the following code in the project file *.pro:

Other development environments such as VS can refer to the reference material (the first one) given later in this article.

  Some basic features of Eigen:

The type of matrix in Eigen is generally represented by a similar matrixxxx, which can be used to determine its data type, such as ' d ' for a double not to represent an integer; ' F ' stands for float; ' I ' stands for integers; ' C ' stands for complex, which is plural; ' d ' denotes dynamic, which means that some dimensions in the matrix are indeterminate ... For example, say: MATRIX2CD, represents the 2*2 dimension, each element is a complex number, the real and imaginary parts of the complex are double type.

Eigen need to be very careful about their data types, such as 2 vectors multiply if you get a matrix, the type of elements in the vector and the elements in the matrix must be the same type, or an error will occur.

Here is an example of a simple use of the next Eigen library, this example is very simple, mainly for the use of Eigen have a perceptual knowledge. The experiment code is as follows:

#include <iostream>#include<vector>#include<Eigen/Eigen>using namespaceEigen;using namespacestd;intMain () {eigen::vector2d v1, v2; //variables in the EigenV1 <<5,6;//The default vector is the column vectorcout <<"V1 ="<< Endl << v1 <<Endl; V2<<4,5 ; matrix2d result= v1*V2.transpose (); cout<<"Result:"<< Endl << Result <<Endl;}

  The experimental results are as follows:

  

  Resources:

C + + Matrix processing tool--eigen

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

C + + processing matrix operations: Eigen Library Preliminary Learning use

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.