matrixbase::GetReal

Description

Get the Real part of a Complex matrix.

Syntax

BOOL GetReal( matrix & mReal )

Parameters

mReal
[output] matrix containing the Real part of this Complex matrix

Return

Returns TRUE on successful exit and FALSE on failure.

Examples

EX1

void matrixbase_GetReal_ex1()
{
    matrix<complex> mComplex = {1+2i, 3+4i, 6i, 0, 99};
    mComplex[0][4]=NANUM;
        matrix mReal;
        
        int rc = mComplex.GetReal(mReal);
    if(!rc) 
        printf("Error: GetReal failed. rc=%d\n", rc); 
    else{
        printf("The GetReal matrix is:\n");
        for(int ii=0; ii< mReal.GetNumRows(); ii++){
                        for(int jj=0; jj< mReal.GetNumCols(); jj++) 
                                printf("%g  ", mReal[ii][jj]);
                        printf("\r\n");
        }
    }
}

EX2

// Apply GetReal and GetImaginary functions to the complex cell values of a matrix
void matrixbase_GetReal_ex1()
{
    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 Real part of a Complex matrix. Causes a runtime error if the underlying base type of the matrix is not Complex.

See Also

matrixbase::GetImaginary, matrixbase::GetPhase, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex

header to Include

origin.h