Exemple #1
0
bool SMatrix::Jointer_Right(SMatrix& other)
{
    if(other.nRow()!=nRow()) return FALSE;
	
	if(!AddCols(other.nCol(),ERRORVAL))
		return FALSE;

	Paste(other,0,nCol()-other.nCol());
   
return TRUE;
}
Exemple #2
0
bool SMatrix::Paste(SMatrix& other,int top,int left) const
{
 int i,j,iRow,iCol;

 iRow = other.nRow()>(nRow()-top)  ? (nRow()-top) : other.nRow();
 iCol = other.nCol()>(nCol()-left) ? (nCol()-left): other.nCol();
 
 for(i=0;i<iRow;i++)
	 for(j=0;j<iCol;j++)
		 GetElem(i+top,j+left) = other[i][j];

return TRUE;
}
Exemple #3
0
bool SMatrix::Jointer_Diagonal(SMatrix& other,ELEMTYPE Val)
{
	int iCol;
	
	iCol = nRow()==0 ? other.nCol()-1 : other.nCol();

	if(!AddRows(other.nRow(),Val))
		return FALSE;
	if(!AddCols(iCol,Val))
	    return FALSE;

return Paste(other,nRow()-other.nRow(),nCol()-other.nCol()); 
}
Exemple #4
0
bool SMatrix::CutIn2_Vertical(SMatrix& Left,SMatrix& Right,int iCol)
{
  int i,j;

   if (nCol()==0)
   {
	    Left.ReSize(0,0);
	   Right.ReSize(0,0);
	   return TRUE;
   }

   if(iCol>nCol()||iCol<0) return FALSE;

    if(!Left.ReSize(nRow(),iCol,ERRORVAL))
		return FALSE;

   if(!Right.ReSize(nRow(),nCol()-iCol,ERRORVAL))
	   return FALSE;

	   for(i=0;i<nRow();i++)
          for(j=0;j<iCol;j++)
               Left[i][j] = GetElem(i,j);
       
	   for(i=0;i<nRow();i++)
		   for(j=0;j<Right.nCol();j++)
			  Right[i][j] = GetElem(i,j+iCol);
			   
   return TRUE;
}
Exemple #5
0
bool SMatrix::Jointer_bottom(SMatrix& other)
{
	if(other.nCol()!=nCol()) return FALSE;
	
	if(!AddRows(other.nRow(),ERRORVAL))
		return FALSE;	
	
return Paste(other,nRow()-other.nRow(),0);
}
Exemple #6
0
SMatrix operator * (double value ,const SMatrix& other)
{
	int i,j;
	
	SMatrix result(other);
	
    for (i=0;i<other.nRow();i++)
		for(j=0;j<other.nCol();j++)
				result[i][j] *= value; 

return result;
}
Exemple #7
0
SMatrix SMatrix::operator * (const SMatrix& other) const
{
	int i,j,k;
	
	SMatrix result(this->nRow(),other.nCol());
	
	if(other.nRow()!=this->nCol())
	{
		for (i=0;i<result.nRow();i++)
			for (j=0;j<result.nCol();j++)
				result.GetElemP(i,j)->val = ERRORVAL;
			return result;
	}
	
    for (i=0;i<this->nRow();i++)       //矩阵相乘的计算
		for(j=0;j<other.nCol();j++)
			for(k = 0; k < other.nRow(); k++)
				result[i][j] += this->GetElem(i,k) * other.GetElem(k,j); 
	
return result;
}
Exemple #8
0
ELEMTYPE SMatrix::Distance_E(SMatrix& other) const
{
	     int i,j; 
	ELEMTYPE result = ERRORVAL;

	if(nRow()!=other.nRow()||nCol()!=other.nCol()) return result;

    for(result=0,i=0;i<nRow();i++)
		for(j=0;j<nCol();j++)
		   result += pow(GetElem(i,j)-other[i][j],2);

return sqrt(result);
}
Exemple #9
0
SMatrix::SMatrix(const SMatrix& other)
{
	pHead = new HeadNode;
	
	 pHead->nRow = 0;
	 pHead->nCol = 0;
   pHead->pFirst = NULL;

	  AddRows(other.nRow(),0.0);
	  AddCols(other.nCol()-1,0.0);

	  *this += other; 
}
Exemple #10
0
SMatrix SMatrix::GetPart(int left,int top,int bottom,int right) const
{
    int i,j;

    SMatrix result;

	if(left>right||top>bottom||right>=nCol()||bottom>=nRow()||left<0||top<0||right<0||bottom<0) return result;

    if(!result.ReSize(bottom-top+1,right-left+1,ERRORVAL))
		return result;
	
    for(i=0;i<result.nRow();i++)
		for(j=0;j<result.nCol();j++)
			result[i][j] = GetElem(i+left,j+top);

return result;
}
Exemple #11
0
SMatrix SMatrix::operator - (const SMatrix& other) const
{
	int i,j;
	
	SMatrix result(*this);
	
	if(other.nRow()!=this->nRow()||other.nCol()!=this->nCol())
	{
		for (i=0;i<result.nRow();i++)
			for (j=0;j<result.nCol();j++)
				result.GetElemP(i,j)->val = ERRORVAL;
			return result;
	}
	
	result -= other;
	
return result;
}