Components of Complex Matrices
The real and imaginary parts of complex matrices are also easy to access. The member functions real() and imag() return a matrix containing the real or imaginary part. For example, consider the following code:
#include <rw/lapack/hermmat.h>
#include <rw/lapack/symmat.h>
#include <rw/lapack/skewmat.h>
int main()
{
RWHermMat<DComplex> H(5, 5); // 1
RWSymMat<double> Hreal = real(H); // 2
RWSkewMat<double> Himag = imag(H); // 3
return 0;
}
In this example, the matrices Hreal and Himag actually refer to the data of H; that is, they present different views of the same data as H. You can use this fact to conveniently modify the real and imaginary parts of a complex matrix in the following example:
#include <rw/cgenmat.h>
#include <rw/dgenmat.h>
int main()
{
RWGenMat<DComplex> A(5,5, rwUninitialized); // 1
real(A) = 1; // 2
imag(A) = -1; // 3
return 0;
}