Browse Source

修改Mij函数为余子式值,添加MijMatrix函数

master
blobt 4 years ago
parent
commit
c8e2a4373a
  1. BIN
      .vs/3dMath/v15/.suo
  2. BIN
      .vs/3dMath/v15/Browse.VC.opendb
  3. 54
      GMath.cpp
  4. 8
      GMath.h
  5. 30
      main.cpp

BIN
.vs/3dMath/v15/.suo

BIN
.vs/3dMath/v15/Browse.VC.opendb

54
GMath.cpp

@ -1022,7 +1022,7 @@ int Nullity(const GMatrix & m)
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 r = m.GetRowNum();
@ -1055,16 +1055,17 @@ GMatrix Mij(const GMatrix & m, int rom, int col)
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);
GMatrix M = MijMatrix(m, r, c);
return Det(M);
}
float Cij(const GMatrix & m, int r, int c)
{
GMatrix M = MijMatrix(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];//行列式运算的-号只能影响一行
}
}
return ret;
return t*Det(M);
}
float Det(const GMatrix & m)
@ -1083,17 +1084,42 @@ float Det(const GMatrix & m)
}
else {
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;
}
GLine::GLine(const GPoint3 & _p, const GVector3 & _v)
{
p = _p;

8
GMath.h

@ -200,9 +200,13 @@ public:
friend int Rank(const GMatrix& m);//
friend int Nullity(const GMatrix& m);//
friend GMatrix Mij(const GMatrix& m, int r, int c); //
friend GMatrix Cij(const GMatrix& m, int r, int c); //
friend GMatrix MijMatrix(const GMatrix& m, int r, int c); //
friend float Mij(const GMatrix& m, int r, int c); //
friend float Cij(const GMatrix& m, int r, int c); //
friend float Det(const GMatrix& m);
friend GMatrix Inverse(const GMatrix& m);
friend GMatrix Transpose(const GMatrix& m);
friend GMatrix Adjoint(const GMatrix& m);//
private:
int r;

30
main.cpp

@ -2,20 +2,30 @@
int main() {
float m1[] = {
2, 3, 8, 4,
6, 0, -3, 8,
-1, 3, 2, 9,
2, 0, 4, 10
float a[] = {
0, 0, 0, 2,
0, 0, 2, 1,
0, 2, 1, 2,
2, 1, 2, 3
};
GMatrix A(4, 4, a);
//cout << B*A << endl;
cout << Det(A) << endl;
GMatrix M1(4, 4, m1);
GMatrix M2(4, 4, m1);
/*float a[] = {
1,0,
1,4
};
GMatrix A(2, 2, a);
M1.SetInverse();
cout << M1 << endl;
float c[] = {
0,1,
1,0
};
GMatrix C(2, 2, c);
cout << A*A << endl;*/
return 0;
return 0;
}
Loading…
Cancel
Save