2.2.3.9.29 matrixbase::GetImaginaryGetImaginary
Description
Get the Imaginary part of a Complex matrix.
Syntax
BOOL GetImaginary( matrix & mImag )
Parameters
- mImag
- [output] matrix containing the Imaginary part of this Complex matrix
Return
Returns TRUE on successful exit and FALSE on failure.
Examples
EX1
void matrixbase_GetImaginary_ex1()
{
matrix<complex> mComplex = {1+2i, 3+4i, 6i, 0, 99};
mComplex[0][4]=NANUM;
matrix mImag;
int rc = mComplex.GetImaginary(mImag);
if(!rc)
printf("Error: GetImaginary failed. rc=%d\n", rc);
else{
printf("The GetImaginary matrix is:\n");
for(int ii=0; ii< mImag.GetNumRows(); ii++){
for(int jj=0; jj< mImag.GetNumCols(); jj++)
printf("%g ", mImag[ii][jj]);
printf("\r\n");
}
}
}
EX2
// Apply GetReal and GetImaginary functions to the complex cell values of a matrix
void matrixbase_GetImaginary_ex2()
{
matrix<complex> mComplex = {1+2i, 3+4i, 6i, 0, 99};
mComplex[0][4]=NANUM;
// Input matrix is:
// {1+2i, 3+4i, 6i, 0, --}
// Output real matrix is:
// {1, 3, 0, 0, --}
// Output imaginary matrix is:
// {2, 4, 6, 0, 0}
matrix mReal1, mImag1;
PageBase pgbase;
MatrixPage MatPg1;
MatPg1.Create("Origin");
MatrixLayer MatLy1 = MatPg1.Layers(0);
MatLy1.SetInternalData(FSI_COMPLEX); // Set the internal data type to complex
Matrix<complex> Mat1(MatLy1);
pgbase = Project.Pages(); // Get the active page
pgbase.Rename("Original");
Mat1 = mComplex;
printf(" Original matrix is %s.\n",Mat1.GetName());
printf("\n");
MatrixPage MatPg2;
MatPg2.Create("Origin");
MatrixLayer MatLy2 = MatPg2.Layers(0);
Matrix Mat2(MatLy2);
pgbase = Project.Pages(); // Get the active page
pgbase.Rename("Real");
int rc=mComplex.GetReal( mReal1 ); // mReal1 = {1,3,0,0,--};
if(!rc)
printf(" Error: GetReal failed.\n");
else {
Mat2 = mReal1;
printf(" Extracted matrix by GetReal is %s.\n",Mat2.GetName());
printf(" Observe that the result value of GetReal on NANUM is NANUM.\n");
}
printf("\n");
MatrixPage MatPg3;
MatPg3.Create("Origin");
MatrixLayer MatLy3 = MatPg3.Layers(0);
Matrix Mat3(MatLy3);
pgbase = Project.Pages(); // Get the active page
pgbase.Rename("Imaginary");
rc=mComplex.GetImaginary( mImag1 ); // mImag1 = {2,4,6,0,0};
if(!rc)
printf(" Error: GetImaginary failed.\n");
else {
Mat3 = mImag1;
printf(" Extracted matrix by GetImaginary is %s.\n",Mat3.GetName());
printf(" Observe that each result value is a real number.\n");
printf(" Observe that the result value of GetImaginary on NANUM is 0.\n");
}
}
Remark
Get the Imaginary part of a Complex matrix. Causes a runtime error if the underlying base type of the matrix is not Complex.
See Also
MatrixLayer::SetInternalData,
matrixbase::GetReal, matrixbase::GetPhase, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex
Header to Include
origin.h
|