2.1.17.7.7 Trace


Description

These four functions will give the trace of a matrix. We do not support every matrix type.

Syntax

int Trace( matrix<short> & matSource, int & nSum )


int Trace( matrix<int> & matSource, int & nSum )


int Trace( matrix<double> & matSource, double & dSum )


int Trace( matrix<complex> & matSource, complex & cSum )

Parameters

matSource
[input]The source short type matrix
nSum
[output]These are the variables to store the trace


matSource
[input]The source int type matrix
nSum
[output]These are the variables to store the trace


matSource
[input]The source double type matrix
dSum
[output]These are the variables to store the trace


matSource
[input]The source complex type matrix
cSum
[output]These are the variables to store the trace

Return

Returns 0 on successful exit

Examples

EX1

int Matrix_Trace_ex1()
{
   matrix matSource = {{1,2,3},{5,6,7},{9,10,11}};
   printf("the source matrix\n");
   int ii, jj;
   int nNumCols = matSource.GetNumCols();
   int nNumRows = matSource.GetNumRows();
   for(ii = 0; ii < nNumRows; ii++)
   {
       for(jj = 0; jj < nNumCols; jj++)
           printf("%f  ",matSource[ii][jj]);
       printf("\n");    
   }
   int nRet;
   double dTrace;
   if(nRet = Trace(matSource, dTrace))
       return nRet;
   printf("The trace is: %f",dTrace);
   return nRet;
}

Remark

See Also

SVD

Header to Include

origin.h

Reference