- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
#include "stdafx.h"
#define n 3
void PrintMatrix(vector<vector<float> >imatrix)
{
for (size_t i = 0; i < n; ++i)
{
cout << endl;
for (size_t j = 0; j < n; ++j)
{
cout.precision(3);
cout << " " << imatrix[i][j];
}
}
}
void ReverseMatrix(vector<vector<float> >imatrix, float determ)
{
float t = 0;
for (size_t i = 0; i < n; i++)
{
for (size_t j = 0; j < n; j++)
{
t = imatrix[i][j] * (1 / determ);
imatrix[i][j] = t;
}
}
PrintMatrix(imatrix);
}
void TransposedMatrix(vector<vector<float> >imatrix, float determ)
{
float t = 0;
for (size_t i = 0; i < n; i++)
{
for (size_t j = i; j < n; j++)
{
t = imatrix[i][j];
imatrix[i][j] = imatrix[j][i];
imatrix[j][i] = t;
}
}
ReverseMatrix(imatrix, determ);
}
void MinorMatrix(vector<vector<float> >imatrix, float determ)
{
vector<vector<float> >imatrix2(n);
float t = 0.0;
for (size_t i = 0; i < n; ++i)
{
imatrix2[i].resize(n);
for (size_t j = 0; j < n; ++j)
{
if (i == 0)
{
switch (j){
case 0: imatrix2[i][j] = imatrix[i + 1][j + 1] * imatrix[i + 2][j + 2] - imatrix[i + 1][j + 2] * imatrix[i + 2][j + 1]; t = imatrix2[i][j];break;
case 1: imatrix2[i][j] = (imatrix[i + 1][j - 1] * imatrix[i + 2][j + 1] - imatrix[i + 2][j - 1] * imatrix[i + 1][j + 1]) * (-1); t = imatrix[i][j]; break;
case 2: imatrix2[i][j] = imatrix[i + 1][j - 2] * imatrix[i + 2][j - 1] - imatrix[i + 1][j - 1] * imatrix[i + 2][j - 2];t = imatrix2[i][j];break;
}
}
if (i == 1)
{
switch (j){
case 0: imatrix2[i][j] = (imatrix[i - 1][j + 1] * imatrix[i + 1][j + 2] - imatrix[i - 1][j + 2] * imatrix[i + 1][j + 1]) * (-1);t = imatrix2[i][j];break;
case 1:imatrix2[i][j] = imatrix[i - 1][j - 1] * imatrix[i + 1][j + 1] - imatrix[i - 1][j + 1] * imatrix[i + 1][j - 1];t = imatrix2[i][j];break;
case 2:imatrix2[i][j] = (imatrix[i - 1][j - 2] * imatrix[i + 1][j - 1] - imatrix[i - 1][j - 1] * imatrix[i + 1][j - 2]) * (-1);t = imatrix2[i][j];break;
}
}
if (i == 2)
{
switch (j){
case 0: imatrix2[i][j] = imatrix[i - 2][j + 1] * imatrix[i - 1][j + 2] - imatrix[i - 1][j + 1] * imatrix[i - 2][j + 2];t = imatrix2[i][j];break;
case 1:imatrix2[i][j] = (imatrix[i - 2][j - 1] * imatrix[i - 1][j + 1] - imatrix[i - 1][j - 1] * imatrix[i - 2][j + 1]) * (-1);t = imatrix2[i][j];break;
case 2: imatrix2[i][j] = imatrix[i - 2][j - 2] * imatrix[i - 1][j - 1] - imatrix[i - 2][j - 1] * imatrix[i - 1][j - 2];t = imatrix2[i][j];break;
}
}
}
}
imatrix.clear();
TransposedMatrix(imatrix2, determ);
}
void FindDeterminant(vector<vector<float> >imatrix)
{
float determ = imatrix[0][0] * imatrix[1][1] * imatrix[2][2] + imatrix[2][0] * imatrix[0][1] * imatrix[1][2] + imatrix[1][0] * imatrix[2][1] * imatrix[0][2] - imatrix[2][0] * imatrix[1][1] * imatrix[0][2] - imatrix[0][0] * imatrix[2][1] * imatrix[1][2] - imatrix[1][0] * imatrix[0][1] * imatrix[2][2];
if (determ == 0)
{
cout << "Determinant = 0 ==> Reverse matrix doesn't exist";
system("pause");
exit(0);
}
MinorMatrix(imatrix, determ);
}
Вот таких студентов учить приходится. От оно как матрицы 3*3 инвертируют.
Больше лучей ненависти тут:
https://github.com/PLaGInc/Lab1/issues/3