Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Member function in Eigen math library for vector magnitude

Tags:

c++

vector

eigen

I have been trying to find a method that computes the magnitude of a vector in Eigen and I was not able to. Can somebody provide me with the function name of just if it doesn't exist?

I can create a global method that does the job but I prefer not to.

like image 731
Alex Avatar asked Apr 10 '11 16:04

Alex


People also ask

What is Eigen column vector?

... in Eigen, vectors are just a special case of matrices, with either 1 row or 1 column. The case where they have 1 column is the most common; such vectors are called column-vectors, often abbreviated as just vectors. In the other case where they have 1 row, they are called row-vectors.

How do I use Eigen library?

In order to use Eigen, you just need to download and extract Eigen's source code (see the wiki for download instructions). In fact, the header files in the Eigen subdirectory are the only files required to compile programs using Eigen. The header files are the same for all platforms.

How do I resize an eigen matrix?

Resizing. The current size of a matrix can be retrieved by rows(), cols() and size(). These methods return the number of rows, the number of columns and the number of coefficients, respectively. Resizing a dynamic-size matrix is done by the resize() method.


2 Answers

You want .norm(). Note that there's also .squaredNorm(), .normalized() and .normalize().

like image 61
timday Avatar answered Sep 28 '22 10:09

timday


The method you're looking for is .norm().

like image 36
Benoit Jacob Avatar answered Sep 28 '22 09:09

Benoit Jacob