C++ Armadillo :: Real and Imaginary part














































C++ Armadillo :: Real and Imaginary part



---------------------------------------------------------------------------------------------------------------
Description::
This is the basic C++ program of C++ armadillo library which shows how to find real and imaginary part of the given matrix. It can be carried out by the help of inbuilt functions "real" and "imag" in armadillo library.
It is used to extract the imaginary/real part of a complex matrix or cube
---------------------------------------------------------------------------------------------------------------
Program::

#include <iostream>
#include <armadillo>
using namespace std;
using namespace arma;

int main()
{
//initialize the random generator
//Create a 5 x 5 random matrix and printing it
cx_mat C = randu<cx_mat>(5,5); //Generating a matrix of 5 x 5
mat A = imag(C); //Imaginary part of matrix mat B = real(C); //Real part of matrix cout << "Matrix C::\n"<<endl;
cout << C << endl;
cout << "Matrix A(Imaginary part)::\n"<<endl;
cout << A << endl;
cout << "Matrix B(Real part)::\n"<<endl;
cout << B << endl;
return 0; }
---------------------------------------------------------------------------------------------------------------
Commands to run program on terminal::
g++ filename.cpp -o objectname -O2 -larmadillo

$ ./objectname
---------------------------------------------------------------------------------------------------------------
Output::

Matrix C:: (+7.868e-01,+2.505e-01) (+2.742e-01,+5.610e-01) (+2.393e-01,+3.201e-01) (+4.599e-01,+2.573e-01) (+5.050e-01,+6.962e-01) (+7.107e-01,+9.467e-01) (+1.400e-01,+5.439e-01) (+9.105e-01,+1.648e-01) (+7.770e-01,+5.839e-01) (+9.122e-02,+9.071e-01) (+1.927e-02,+4.049e-01) (+5.219e-01,+8.571e-01) (+2.455e-01,+1.983e-01) (+9.503e-01,+4.381e-01) (+3.091e-02,+1.520e-01) (+2.513e-01,+2.271e-02) (+4.998e-01,+4.194e-01) (+7.159e-01,+9.678e-01) (+3.223e-01,+5.324e-01) (+9.815e-01,+6.204e-01) (+5.206e-01,+3.447e-01) (+7.443e-01,+2.492e-01) (+7.694e-01,+8.071e-02) (+2.564e-01,+4.554e-02) (+2.988e-01,+3.613e-01) Matrix A(Imaginary part):: 0.2505 0.5610 0.3201 0.2573 0.6962 0.9467 0.5439 0.1648 0.5839 0.9071 0.4049 0.8571 0.1983 0.4381 0.1520 0.0227 0.4194 0.9678 0.5324 0.6204 0.3447 0.2492 0.0807 0.0455 0.3613 Matrix B(Real part):: 0.7868 0.2742 0.2393 0.4599 0.5050 0.7107 0.1400 0.9105 0.7770 0.0912 0.0193 0.5219 0.2455 0.9503 0.0309 0.2513 0.4998 0.7159 0.3223 0.9815 0.5206 0.7443 0.7694 0.2564 0.2988


More Articles of Shubham Loya:

Name Views Likes
C++ OpenCV cv::trace() 1383 1
C++ Armadillo :: Real and Imaginary part 1388 1
C++ OpenCV cv::perspectiveTransform() 4670 1
C++ Armadillo :: find_nonfinite 652 2
C++ Armadillo introduction and installation 535 1
C++ Armadillo :: Kron 1119 1
C++ Armadillo :: Accessing row and column and operations on it 1041 1
C++ Armadillo :: cond 421 2
C++ Armadillo :: pseudo-inverse 2480 1
C++ OpenCV cv::flip() 1526 1
C++ OpenCV cv::transpose() 6110 1
C++ Armadillo :: any 469 2
C++ Armadillo :: Max and Min of matrices 785 1
C++ OpenCV cv::pow() 2110 1
C++ Armadillo :: fliplr and flipud 892 2
C++ Armadillo :: Sort 1038 1
C++ Armadillo :: Determinant of Matrix 784 1
C++ Armadillo :: Indices of Unique elements of matrix 805 1
C++ Armadillo :: eps 432 3
C++ Armadillo :: Inverse 1168 1
C++ Armadillo :: Transpose of Matrix 1011 1
C++ Armadillo :: Basic Arithmetic Operations 420 1
C++ Armadillo :: Cross Product of vectors 1052 4
C++ OpenCV program to play a video 1037 1
C++ Armadillo :: Diagonal of Matrix 802 1
C++ Armadillo :: Absolute value of Matrix 1009 1
C++ Armadillo :: Conj 388 2
C++ Armadillo :: expmat 814 2
C++ OpenCV Input from Camera 1691 1
C++ OpenCV program to convert BGR image to grayscale image 4883 1
C++ Armadillo :: Intersect 665 2
C++ Armadillo :: Nonzeros 863 2
C++ Armadillo :: Dot Product of vectors 1462 2
C++ OpenCV:: Transforming BGR image to Grey scale image 526 2
C++ OpenCV to rotate an image 10002 1
C++ Armadillo :: Unique elements of matrix 715 1
C++ Armadillo :: Log Determinant 724 1
C++ Armadillo :: Sort_index 1301 2
C++ Armadillo :: Max Min 1371 1
C++ Armadillo :: Shift 754 1
C++ Armadillo :: Square root of Matrix 1513 1
C++ OpenCV cv::cvtColor() 2010 1

Comments