Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1.  public static double[,] GetMinor(double[,] matrix, int row, int column)
  2.         {
  3.             if (matrix.GetLength(0) != matrix.GetLength(1)) throw new Exception(" Число строк в матрице не совпадает с числом столбцов");
  4.             double[,] buf = new double[matrix.GetLength(0) - 1, matrix.GetLength(0) - 1];
  5.             for (int i = 0; i < matrix.GetLength(0); i++)
  6.                 for (int j = 0; j < matrix.GetLength(1); j++)
  7.                 {
  8.                     if ((i != row) || (j != column))
  9.                     {
  10.                         if (i > row && j < column) buf[i - 1, j] = matrix[i, j];
  11.                         if (i < row && j > column) buf[i, j - 1] = matrix[i, j];
  12.                         if (i > row && j > column) buf[i - 1, j - 1] = matrix[i, j];
  13.                         if (i < row && j < column) buf[i, j] = matrix[i, j];
  14.                     }
  15.                 }
  16.             return buf;
  17.         }
  18.         public static double Determ(double[,] matrix)
  19.         {
  20.             if (matrix.GetLength(0) != matrix.GetLength(1)) throw new Exception(" Число строк в матрице не совпадает с числом столбцов");
  21.             double det = 0;
  22.             int Rank = matrix.GetLength(0);
  23.             if (Rank == 1) det = matrix[0, 0];
  24.             if (Rank == 2) det = matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];
  25.             if (Rank > 2)
  26.             {
  27.                 for (int j = 0; j < matrix.GetLength(1); j++)
  28.                 {
  29.                     det += Math.Pow(-1, 0 + j) * matrix[0, j] * Determ(GetMinor(matrix, 0, j));
  30.                 }
  31.             }
  32.             return det;
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement