| 2.1.17.7.7 Trace
 DescriptionThese four functions will give the trace of a matrix. We do not support every matrix type.
 Syntaxint 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
 ReturnReturns 0 on successful exit
 ExamplesEX1
 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;
}RemarkSee AlsoSVD
 Header to Includeorigin.h
 Reference |