|
@ -1022,7 +1022,7 @@ int Nullity(const GMatrix & m) |
|
|
return m.GetColNum() - rank; |
|
|
return m.GetColNum() - rank; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
GMatrix Mij(const GMatrix & m, int rom, int col) |
|
|
|
|
|
|
|
|
GMatrix MijMatrix(const GMatrix & m, int rom, int col) |
|
|
{ |
|
|
{ |
|
|
int i,j = 0; |
|
|
int i,j = 0; |
|
|
int r = m.GetRowNum(); |
|
|
int r = m.GetRowNum(); |
|
@ -1055,16 +1055,17 @@ GMatrix Mij(const GMatrix & m, int rom, int col) |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
GMatrix Cij(const GMatrix & m, int r, int c) |
|
|
|
|
|
|
|
|
float Mij(const GMatrix & m, int r, int c) |
|
|
{ |
|
|
{ |
|
|
GMatrix ret = Mij(m, r, c); |
|
|
|
|
|
int t = pow(-1, r + c); |
|
|
|
|
|
if (t == -1) { |
|
|
|
|
|
for (int i = 0; i < ret.GetColNum(); i++) { |
|
|
|
|
|
ret[0][i] = -ret[0][i];//行列式运算的-号只能影响一行
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
GMatrix M = MijMatrix(m, r, c); |
|
|
|
|
|
return Det(M); |
|
|
} |
|
|
} |
|
|
return ret; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float Cij(const GMatrix & m, int r, int c) |
|
|
|
|
|
{ |
|
|
|
|
|
GMatrix M = MijMatrix(m, r, c); |
|
|
|
|
|
int t = pow(-1, r + c); |
|
|
|
|
|
return t*Det(M); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
float Det(const GMatrix & m) |
|
|
float Det(const GMatrix & m) |
|
@ -1083,14 +1084,39 @@ float Det(const GMatrix & m) |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
for (i = 0; i < c; i++) { |
|
|
for (i = 0; i < c; i++) { |
|
|
//GMatrix t = Mij(m, 0, i);
|
|
|
|
|
|
//ret += pow(-1, 0+ i) * m[0][i] * Det(t);
|
|
|
|
|
|
GMatrix t = Cij(m, 0, i); |
|
|
|
|
|
//cout << t << endl;
|
|
|
|
|
|
ret += m[0][i] * Det(t); |
|
|
|
|
|
|
|
|
GMatrix t = MijMatrix(m, 0, i); |
|
|
|
|
|
ret += pow(-1, 0+ i) * m[0][i] * Det(t); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GMatrix Inverse(const GMatrix & m) |
|
|
|
|
|
{ |
|
|
|
|
|
GMatrix ret(m); |
|
|
|
|
|
ret.SetInverse(); |
|
|
|
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GMatrix Transpose(const GMatrix & m) |
|
|
|
|
|
{ |
|
|
|
|
|
GMatrix ret(m); |
|
|
|
|
|
ret.SetTranspose(); |
|
|
|
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GMatrix Adjoint(const GMatrix & m) |
|
|
|
|
|
{ |
|
|
|
|
|
GMatrix tM = Transpose(m); |
|
|
|
|
|
GMatrix ret(tM.r, tM.c); |
|
|
|
|
|
|
|
|
|
|
|
int i, j = 0; |
|
|
|
|
|
for (i = 0; i < tM.r; i++) { |
|
|
|
|
|
for (j = 0; j < tM.c; j++) { |
|
|
|
|
|
ret[i][j] = Cij(tM, i, j); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|