Complex

 

Using Complex Values With Origin C Functions

Complex values can be passed into and returned from Origin C functions. The following Origin C code is a simple example.

complex myFunction(double x, int n, complex C)
{
    complex cc;
    cc.m_re = C.m_re * x;
    cc.m_im = C.m_im + n;
    return cc;
}

void testMyFunction()
{
    complex C1(4.5, 7.8);
    complex C2 = myFunction(1.2, 3, C1);
    printf("real == %f\nimag == %f\n", C2.m_re, C2.m_im);
}

Access complex Data from Worksheet

// make sure data type is complex in the second column in active worksheet window.
void GetComplexDataset()
{
        Worksheet wks = Project.ActiveLayer();
        if( wks ) // if active layer is Worksheet
        {
                Dataset<complex> ds(wks, 1);
                        
                vector vPhase;
                int nRet = ds.GetPhase(vPhase);
                if( 0 != nRet ) // 0 for success
                        printf("Fail to get phase");
                
                // add phase result to a new column
                Dataset dsPhase(wks, wks.AddCol());
                dsPhase = vPhase;          
        }
}

Access complex Data from Matrix

// make sure data type is complex in the active matrix window.
void GetComplexMatrix()
{
        MatrixLayer ml = Project.ActiveLayer();
        if( ml )
        {
                Matrix<complex> mat(ml, 0);
                
                matrix matPhase;
                if( !mat.GetPhase(matPhase) )
                        printf("Fail to get phase");
        }
}