Ejemplo n.º 1
0
matrix<T> matrix<T>::adjoint(void)
{
#ifdef _DEBUG
  if (this->dims[0]!=this->dims[1])
    FatalErrorST("Adjoint only meaningful for square matrices.");
#endif
  matrix<T> adj(this->dims[0],this->dims[1]);

  int signRow = -1;
  matrix<T> Minor(this->dims[0]-1,this->dims[1]-1);
  for (int row=0; row<this->dims[0]; row++) {
    signRow *= -1;
    int sign = -1*signRow;
    for (int col=0; col<this->dims[1]; col++) {
      sign *= -1;
      // Setup the minor matrix (expanding along row, col)
      int i0 = 0;
      for (int i=0; i<this->dims[0]; i++) {
        if (i==row) continue;
        int j0 = 0;
        for (int j=0; j<this->dims[1]; j++) {
          if (j==col) continue;
          Minor(i0,j0) = this->operator()(i,j);
          j0++;
        }
        i0++;
      }
      // Recall: adjoint is TRANSPOSE of cofactor matrix
      adj(col,row) = sign*Minor.det();
    }
  }

  return adj;
}
Ejemplo n.º 2
0
 bool Version::operator<=(Version other)
 {
   if (Major()<other.Major()) {
      return true;
   } else if (Major()==other.Major() && Minor()<other.Minor()) {
      return true;
   } else if (Major()==other.Major() && Minor()==other.Minor() && Micro()<=other.Micro()) {
      return true;
   }
   return false;
 }
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
//  virtual Real Cofactor(int r, int c) const
//------------------------------------------------------------------------------
Real Rmatrix::Cofactor(int r, int c) const
{
   #ifdef DEBUG_DETERMINANT
      MessageInterface::ShowMessage(wxT("Entering Cofactor with r     = %d and c     = %d\n"), r, c);
      MessageInterface::ShowMessage(wxT("                   and rowsD = %d and colsD = %d\n"), rowsD, colsD);
   #endif
   if (isSizedD == false)
   {
      throw TableTemplateExceptions::UnsizedTable();
   }

   if (rowsD != colsD)
      throw Rmatrix::NotSquare();
   if (rowsD > 9)
   {
      wxString errmsg = wxT("GMAT Cofactor method not yet optimized.  ");
      errmsg += wxT("Currently limited to matrices of size 9x9 or smaller.");
      throw UtilityException(errmsg);
   }
   Rmatrix Minor(rowsD - 1, colsD - 1);
   Real Cof;
  
   // build the minor matrix
   int i, j, minorI, minorJ;
   for (i = 0, minorI = -1; i < rowsD; i++) 
   {
      if (i != r) 
      {
         minorI++;
         for ( j = 0, minorJ = -1; j < colsD; j++) 
         { 
            if (j != c) 
            {
               minorJ++;
               Minor(minorI, minorJ) = elementD[i*colsD + j]; 
            } // if (j != c) 
         } // for (j = ...
      } // if (i != r)
   } // for (i = ...
   #ifdef DEBUG_DETERMINANT
      MessageInterface::ShowMessage(wxT("about to call Determinant on minor: \n%s\n"), (Minor.ToString()).c_str());
   #endif

   Cof = Minor.Determinant();

   // if r+c is odd Cof is negative
   if ((r+c)%2 == 1)
      Cof = - Cof;
   return Cof;
}
Ejemplo n.º 4
0
// return determinant of a square matrix
double Matrix::determinant() const {
	assert(mRows == mCols);  // must be square matrix

  double d = 0;    // value of the determinant
  int rows = mRows;
  int cols = mCols;

  if (rows == 1) {
    // this is a 1 x 1 matrix
    d = p[0][0];
  } else if (rows == 2) {
    // this is a 2 x 2 matrix
    // the determinant of [a11,a12;a21,a22] is det = a11*a22-a21*a12
    //d = this.get(1, 1) * this.get(2, 2) - this.get(2, 1) * this.get(1, 2);
    d = p[0][0] * p[1][1] - p[1][0] * p[0][1];
  } else {
    // this is a matrix of 3 x 3 or larger
    for (int c = 1; c <= cols; c++) {
      Matrix M = Minor(1, c);
      //d += pow(-1, 1+c) * a(1, c) * Det(M);
      d += (c%2 + c%2 - 1) * p[0][c-1] * M.determinant(); // faster than with pow()
    }
  }

  return d;
}
Ejemplo n.º 5
0
String Version::AsString()
{
   String v = String().Format( "PCL %02d.%02d.%02d.%04d", Major(), Minor(), Release(), Build() );
   if ( BetaRelease() != 0 )
      v.Append( String().Format( " beta %d", BetaRelease() ) );
   return v;
}
Ejemplo n.º 6
0
std::string Version::str()
{
	std::ostringstream v;
	v << Major() << '.' << Minor() << '.' << Revision();
#ifdef PWIZ_USER_VERSION_INFO_H
	v << " (" << PWIZ_USER_VERSION_INFO_H_STR << ")";
#endif
	return v.str();
}
Ejemplo n.º 7
0
String PixInsightVersion::AsString( bool withCodename )
{
   Initialize();
   String v = String().Format( "PixInsight %s%02d.%02d.%02d.%04d",
               LE() ? "LE " : "", Major(), Minor(), Release(), Build() );
   if ( BetaRelease() != 0 )
      v.Append( String().Format( " %s%d", (BetaRelease() < 0) ? "RC" : "beta ", Abs( BetaRelease() ) ) );
   if ( withCodename )
      v.Append( ' ' + Codename() );
   if ( Confidential() )
      v.Append( " (confidential)" );
   return v;
}
Ejemplo n.º 8
0
double matrix<T>::det()
{
#ifdef _DEBUG
  if (this->dims[0]!=this->dims[1])
    FatalErrorST("Determinant only meaningful for square matrices.");
#endif
  if (this->dims[0] == 1) {
    return this->data[0];
  }
  else if (this->dims[0] == 2) {
    // Base case
    return this->data[0]*this->data[3] - this->data[1]*this->data[2];
  }
  else {
    // Use minor-matrix recursion
    double Det = 0;
    int sign = -1;
    matrix<T> Minor(this->dims[0]-1,this->dims[1]-1);
    for (int row=0; row<this->dims[0]; row++) {
      sign *= -1;
      // Setup the minor matrix (expanding along first column)
      int i0 = 0;
      for (int i=0; i<this->dims[0]; i++) {
        if (i==row) continue;
        for (int j=1; j<this->dims[1]; j++) {
          Minor(i0,j-1) = this->operator()(i,j);
        }
        i0++;
      }
      // Add in the minor's determinant
      Det += sign*Minor.det()*this->operator()(row,0);
    }

    return Det;
  }
}
Ejemplo n.º 9
0
  Matrix4 Matrix4::getInverse() const {

    //return ((1.0f / determinant()) * getAdjoint());

    float m00 =  Minor(*this, 5,9,13, 6,10,14, 7,11,15);
    float m01 = -Minor(*this, 4,8,12, 6,10,14, 7,11,15);
    float m02 =  Minor(*this, 4,8,12, 5,9,13,  7,11,15);
    float m03 = -Minor(*this, 4,8,12, 5,9,13,  6,10,14);

    float m10 = -Minor(*this, 1,9,13, 2,10,14, 3,11,15);
    float m11 =  Minor(*this, 0,8,12, 2,10,14, 3,11,15);
    float m12 = -Minor(*this, 0,8,12, 1,9,13,  3,11,15);
    float m13 =  Minor(*this, 0,8,12, 1,9,13,  2,10,14);

    float m20 =  Minor(*this, 1,5,13, 2,6,14, 3,7,15);
    float m21 = -Minor(*this, 0,4,12, 2,6,14, 3,7,15);
    float m22 =  Minor(*this, 0,4,12, 1,5,13, 3,7,15);
    float m23 = -Minor(*this, 0,4,12, 1,5,13, 2,6,14);

    float m30 = -Minor(*this, 1,5,9, 2,6,10, 3,7,11);
    float m31 =  Minor(*this, 0,4,8, 2,6,10, 3,7,11);
    float m32 = -Minor(*this, 0,4,8, 1,5,9,  3,7,11);
    float m33 =  Minor(*this, 0,4,8, 1,5,9,  2,6,10);

    float idet = 1.0f / (mM[0]*m00 - mM[4]*m10 + mM[8]*m20 - mM[12]*m30);

    return Matrix4(
      idet*m00, idet*m01, idet*m02, idet*m03,
      idet*m10, idet*m11, idet*m12, idet*m13,
      idet*m20, idet*m21, idet*m22, idet*m23,
      idet*m30, idet*m31, idet*m32, idet*m33);
  }
Ejemplo n.º 10
0
 float Matrix4::determinant() const {
   return mM[0]  * Minor(*this, 5,9,13, 6,10,14, 7,11,15) -
          mM[4]  * Minor(*this, 1,9,13, 2,10,14, 3,11,15) +
          mM[8]  * Minor(*this, 1,5,13, 2,6,13,  3,7,15) -
          mM[12] * Minor(*this, 1,5,9,  2,6,10,  3,7,11);
 }
Ejemplo n.º 11
0
  Matrix4 Matrix4::getAdjoint() const {
    return Matrix4(

       Minor(*this, 5,9,13, 6,10,14, 7,11,15),
      -Minor(*this, 4,8,12, 6,10,14, 7,11,15),
       Minor(*this, 4,8,12, 5,9,13,  7,11,15),
      -Minor(*this, 4,8,12, 5,9,13,  6,10,14),

      -Minor(*this, 1,9,13, 2,10,14, 3,11,15),
       Minor(*this, 0,8,12, 2,10,14, 3,11,15),
      -Minor(*this, 0,8,12, 1,9,13,  3,11,15),
       Minor(*this, 0,8,12, 1,9,13,  2,10,14),

       Minor(*this, 1,5,13, 2,6,14, 3,7,15),
      -Minor(*this, 0,4,12, 2,6,14, 3,7,15),
       Minor(*this, 0,4,12, 1,5,13, 3,7,15),
      -Minor(*this, 0,4,12, 1,5,13, 2,6,14),

      -Minor(*this, 1,5,9, 2,6,10, 3,7,11),
       Minor(*this, 0,4,8, 2,6,10, 3,7,11),
      -Minor(*this, 0,4,8, 1,5,9,  3,7,11),
       Minor(*this, 0,4,8, 1,5,9,  2,6,10));
  }
Ejemplo n.º 12
0
float cMatrix::Cofactor(int nRow, int nCol)
{
	int nConst = (nRow + nCol) % 2 == 1 ? -1 : 1;
	return nConst * Minor(nRow, nCol);
}
Ejemplo n.º 13
0
	D3DXMATRIX Matrix::Adjoint(const D3DXMATRIX& m)
	{
		return D3DXMATRIX(
			Minor(m, 1, 2, 3, 1, 2, 3),
			-Minor(m, 0, 2, 3, 1, 2, 3),
			Minor(m, 0, 1, 3, 1, 2, 3),
			-Minor(m, 0, 1, 2, 1, 2, 3),

			-Minor(m, 1, 2, 3, 0, 2, 3),
			Minor(m, 0, 2, 3, 0, 2, 3),
			-Minor(m, 0, 1, 3, 0, 2, 3),
			Minor(m, 0, 1, 2, 0, 2, 3),

			Minor(m, 1, 2, 3, 0, 1, 3),
			-Minor(m, 0, 2, 3, 0, 1, 3),
			Minor(m, 0, 1, 3, 0, 1, 3),
			-Minor(m, 0, 1, 2, 0, 1, 3),

			-Minor(m, 1, 2, 3, 0, 1, 2),
			Minor(m, 0, 2, 3, 0, 1, 2),
			-Minor(m, 0, 1, 3, 0, 1, 2),
			Minor(m, 0, 1, 2, 0, 1, 2));
	}