8 .不是
9.不是
18.
// Win32Project1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int m;
int n;
cout << "Please type the row number:" << endl;
cin >> m;
cout << "Please type the col number:" << endl;
cin >> n;
cout << "Please type the Matrix[" << m << "]" << "[" << n << "] elemnts" << endl;
double **Matrix = new double *[m];
for(int i = 0; i < m; i++)
{
Matrix[i] = new double[n];
}
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
cin >> Matrix[i][j];
}
}
cout << "The Matrix is:" << endl;
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
cout << Matrix[i][j] << " ";
}
cout << endl;
}
cout << "The Transform Matrix is:" << endl;
for(int j = 0; j < n; j++)
{
for(int i = 0; i < m; i++)
{
cout << Matrix[i][j] << " ";
}
cout << endl;
}
for(int i = 0; i < m; i++)
{
delete []Matrix[i];
}
delete []Matrix;
return 0;
}
19.
// Win32Project2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
double det4(double M[4][4]);
double det3(double M[3][3]);
double (*mirrorA(double M[4][4], int r, int c,double (&Matrix)[3][3]))[3];
double (*transpose(double M[4][4], double(&transposeMatrix)[4][4]))[4];
double (*cofactorMatrix(double M[4][4], double (&cMatrix)[4][4]))[4];
int _tmain(int argc, _TCHAR* argv[])
{
double Matrix[4][4];
cout << "Please type the Matrix element:" << endl;
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
{
cin >> Matrix[i][j];
}
cout << "The Matrix is:" << endl;
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
cout << Matrix[i][j] <<" ";
}
cout << endl;
}
cout << "The Matrix det is:" << endl;
double det;
det = det4(Matrix);
cout << det << endl;
double coMatrix[4][4];
cofactorMatrix(Matrix, coMatrix);
double adjointMtric[4][4];
transpose(coMatrix, adjointMtric);
cout << "The Inverse Matrix det is:" << endl;
double inverseMatrix[4][4];
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
{
inverseMatrix[i][j] = adjointMtric[i][j] / det;
}
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
cout << inverseMatrix[i][j] << " ";
}
cout << endl;
}
return 0;
}
double det4(double M[4][4])
{
double det = M[0][0]*(M[1][1]*(M[2][2]*M[3][3] -M[2][3]*M[3][2]) -M[1][2]*(M[2][1]*M[3][3] -M[2][3]*M[3][1]) +M[1][3]*(M[2][1]*M[3][2] -M[2][2]*M[3][1]))
-M[0][1]*(M[1][0]*(M[2][2]*M[3][3] -M[2][3]*M[3][2]) -M[1][2]*(M[2][0]*M[3][3] -M[2][3]*M[3][0]) +M[1][3]*(M[2][0]*M[3][2] -M[2][2]*M[3][0]))
+M[0][2]*(M[1][0]*(M[2][1]*M[3][3] -M[2][3]*M[3][1]) -M[1][1]*(M[2][0]*M[3][3] -M[2][3]*M[3][0]) +M[1][3]*(M[2][0]*M[3][1] -M[2][1]*M[3][0]))
-M[0][3]*(M[1][0]*(M[2][1]*M[3][2] -M[2][2]*M[3][1]) -M[1][1]*(M[2][0]*M[3][2] -M[2][2]*M[3][0]) +M[1][2]*(M[2][0]*M[3][1] -M[2][1]*M[3][0]));
return det;
}
double det3(double M[3][3])
{
double det = M[0][0]*(M[1][1]*M[2][2] -M[1][2]*M[2][1]) -M[0][1]*(M[1][0]*M[2][2] -M[1][2]*M[2][0]) +M[0][2]*(M[1][0]*M[2][1] -M[1][1]*M[2][0]);
return det;
}
double (*mirrorA(double M[4][4], int r, int c,double (&Matrix)[3][3]))[3]
{
int m,n;
//double Matrix[3][3];
for(int i = 0; i < 4; i++)
{
if(i == r)
{
continue;
}else if(i < r)
{
m = i;
}else if(i > r)
{
m = i-1;
}
for(int j = 0; j < 4; j++)
{
if(j == c)
{
continue;
}else if(j < c)
{
n = j;
}else if(j > c)
{
n = j-1;
}
Matrix[m][n] = M[i][j];
}
}
return Matrix;
}
double (*transpose(double M[4][4], double(&transposeMatrix)[4][4]))[4]
{
//double transposeMatrix[4][4];
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
{
transposeMatrix[i][j] = M[j][i];
}
return transposeMatrix;
}
double (*cofactorMatrix(double M[4][4], double (&cMatrix)[4][4]))[4]
{
//double cMatrix[4][4];
double mMatrix[3][3];
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
{
cMatrix[i][j] = pow((-1),(i+j))*det3(mirrorA(M, i, j, mMatrix));
}
return cMatrix;
}