ВУЗ:
Составители:
Рубрика:
Андрианова А.А., Исмагилов Л.Н., Мухтарова Т.М.
// оператор траспонирования матрицы
template <class T> Matrix<T> Matrix<T>::operator !()
{
Matrix<T> temp(n, m);
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
temp.a[j][i] = a[i][j];
return temp;
}
// функция получения подматрицы путем вычеркиванмя строки
// с номером i1 и столбца с номером j1
template <class T>
Matrix<T> Matrix<T>::SubMatrix(int i1,int j1)
{
Matrix<T> temp(m - 1, n - 1);
for(int i = 0; i < i1; i++)
{
for(int j = 0; j < j1; j++)
temp.a[i][j] = a[i][j];
for(int j = j1 + 1; j < n; j++)
temp.a[i][j - 1] = a[i][j];
}
for(int i = i1 + 1; i < m; i++)
{
for(int j = 0; j < j1; j++)
temp.a[i - 1][j] = a[i][j];
for(int j = j1 + 1; j < n; j++)
temp.a[i - 1][j - 1] = a[i][j];
}
return temp;
}
// функция вычисления определителя матрицы
template <class T> T Matrix<T>::Determinant()
{
T det = 0;
if(m != n)
throw NonSquareMatrixException();
if(n == 1)
return a[0][0];
Matrix<T> temp(m - 1, n - 1);
for(int j = 0; j < n; j++)
{
temp = SubMatrix(0, j);
if(j % 2 == 0)
det = det + temp.Determinant() * a[0][j];
else
det = det - temp.Determinant() * a[0][j];
220
Андрианова А.А., Исмагилов Л.Н., Мухтарова Т.М. // оператор траспонирования матрицы templateMatrix Matrix ::operator !() { Matrix temp(n, m); for(int i = 0; i < m; i++) for(int j = 0; j < n; j++) temp.a[j][i] = a[i][j]; return temp; } // функция получения подматрицы путем вычеркиванмя строки // с номером i1 и столбца с номером j1 template Matrix Matrix ::SubMatrix(int i1,int j1) { Matrix temp(m - 1, n - 1); for(int i = 0; i < i1; i++) { for(int j = 0; j < j1; j++) temp.a[i][j] = a[i][j]; for(int j = j1 + 1; j < n; j++) temp.a[i][j - 1] = a[i][j]; } for(int i = i1 + 1; i < m; i++) { for(int j = 0; j < j1; j++) temp.a[i - 1][j] = a[i][j]; for(int j = j1 + 1; j < n; j++) temp.a[i - 1][j - 1] = a[i][j]; } return temp; } // функция вычисления определителя матрицы template T Matrix ::Determinant() { T det = 0; if(m != n) throw NonSquareMatrixException(); if(n == 1) return a[0][0]; Matrix temp(m - 1, n - 1); for(int j = 0; j < n; j++) { temp = SubMatrix(0, j); if(j % 2 == 0) det = det + temp.Determinant() * a[0][j]; else det = det - temp.Determinant() * a[0][j]; 220
Страницы
- « первая
- ‹ предыдущая
- …
- 218
- 219
- 220
- 221
- 222
- …
- следующая ›
- последняя »