cMatrix cMatrix::Identity( int nDimension ) { cMatrix matRet(nDimension); for (int i = 0; i < nDimension; ++i) { for (int j = 0; j < nDimension; ++j) { matRet[i][j] = (i == j) ? 1.0f : 0.0f; } } return matRet; }
cMatrix cMatrix::Adjoint() { cMatrix matRet(Dimension()); for (int i = 0; i < Dimension(); ++i) { for (int j = 0; j < Dimension(); ++j) { matRet[i][j] = Cofactor(j, i); } } return matRet; }
cMatrix cMatrix::Transpose() { cMatrix matRet(Dimension()); for (int i = 0; i < Dimension(); ++i) { for (int j = 0; j < Dimension(); ++j) { matRet[i][j] = (*this)[j][i]; } } return matRet; }
cMatrix cMatrix::operator*( float f ) { cMatrix matRet(Dimension()); for (int i = 0; i < Dimension(); ++i) { for (int j = 0; j < Dimension(); ++j) { matRet[i][j] = (*this)[i][j] * f; } } return matRet; }
cMatrix cMatrix::operator-( cMatrix mat ) { cMatrix matRet(Dimension()); for (int i = 0; i < Dimension(); ++i) { for (int j = 0; j < Dimension(); ++j) { matRet[i][j] = (*this)[i][j] - mat[i][j]; } } return matRet; }
MAT trapz(MAT &matX,MAT &matY) { MAT matRet(1,matX.nlength);//估计也用不到二维矩阵……这里先这样吧(不会写) if(matX.nlength!=matY.nlength || matX._row!=1 || matY._row!=1) { return MAT(); } for(int i(1);i<matX.nlength;i++) { double val = (matX.GetValue(0,i) - matX.GetValue(0,i-1))/*delta x*/ *(matY.GetValue(0,i) + matY.GetValue(0,i-1))/*delta h*/ /2 + matRet.GetValue(0,i-1);/*prev sum*/ matRet.SetValue(0,i,val); } return matRet; }
cMatrix cMatrix::operator*( cMatrix mat ) { cMatrix matRet(Dimension()); for (int i = 0; i < Dimension(); ++i) { for (int j = 0; j < Dimension(); ++j) { matRet[i][j] = 0; for (int k = 0; k < Dimension(); ++k) { matRet[i][j] += ((*this)[i][k] * mat[k][j]); } } } return matRet; }