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() 1555 1
C++ Armadillo :: Real and Imaginary part 1632 1
C++ OpenCV cv::perspectiveTransform() 5326 1
C++ Armadillo :: find_nonfinite 792 2
C++ Armadillo introduction and installation 596 1
C++ Armadillo :: Kron 1307 1
C++ Armadillo :: Accessing row and column and operations on it 1404 1
C++ Armadillo :: cond 481 2
C++ Armadillo :: pseudo-inverse 2886 1
C++ OpenCV cv::flip() 1834 1
C++ OpenCV cv::transpose() 6950 1
C++ Armadillo :: any 532 2
C++ Armadillo :: Max and Min of matrices 918 1
C++ OpenCV cv::pow() 2395 1
C++ Armadillo :: fliplr and flipud 1001 2
C++ Armadillo :: Sort 1230 1
C++ Armadillo :: Determinant of Matrix 883 1
C++ Armadillo :: Indices of Unique elements of matrix 958 1
C++ Armadillo :: eps 492 3
C++ Armadillo :: Inverse 1508 1
C++ Armadillo :: Transpose of Matrix 1230 1
C++ Armadillo :: Basic Arithmetic Operations 453 1
C++ Armadillo :: Cross Product of vectors 1274 4
C++ OpenCV program to play a video 1185 1
C++ Armadillo :: Diagonal of Matrix 948 1
C++ Armadillo :: Absolute value of Matrix 1147 1
C++ Armadillo :: Conj 482 2
C++ Armadillo :: expmat 955 2
C++ OpenCV Input from Camera 1947 1
C++ OpenCV program to convert BGR image to grayscale image 5679 1
C++ Armadillo :: Intersect 765 2
C++ Armadillo :: Nonzeros 994 2
C++ Armadillo :: Dot Product of vectors 1664 2
C++ OpenCV:: Transforming BGR image to Grey scale image 580 2
C++ OpenCV to rotate an image 11178 1
C++ Armadillo :: Unique elements of matrix 809 1
C++ Armadillo :: Log Determinant 797 1
C++ Armadillo :: Sort_index 1509 2
C++ Armadillo :: Max Min 1596 1
C++ Armadillo :: Shift 918 1
C++ Armadillo :: Square root of Matrix 1730 1
C++ OpenCV cv::cvtColor() 2322 1

Comments