public static arrays operator -(arrays mass1, arrays mass2) { arrays buf = new arrays(mass1.data.GetLength(1), mass1.data.GetLength(0)); if (mass1.data.GetLength(1) == mass2.data.GetLength(0)) for (int i = 0; i < mass1.data.GetLength(0); i++) { for (int j = 0; j < mass1.data.GetLength(1); j++) { buf.data[i, j] = 0; buf.data[i, j] = mass1.data[i, j] - mass2.data[i, j]; } } else { Console.WriteLine("Error"); Console.ReadLine(); } return buf; }
public static arrays operator /(arrays mass1, arrays mass2) { arrays buf = new arrays(mass1.data.GetLength(1), mass1.data.GetLength(0)); //mass2 return buf; }
public arrays mylt(arrays mass, double a) { for (int k = 0; k < mass.data.GetLength(0); k++) { for (int n = 0; n < mass.data.GetLength(1); n++) { mass.data[k, n] *= (double)a; } } return mass; }
public arrays exponent(arrays mass, int n) { for (int i = 0; i < n; i++) { mass *= mass; } return (mass); }
public arrays mini(int i, int j, arrays mass) { arrays mass1 = mass; arrays mass2 = new arrays(mass.data.GetLength(0)-1 , mass.data.GetLength(1)-1); double max = mass.data[0, 0]; for (int i1 = 0; i1 < mass1.data.GetLength(0); i1++) { for (int j1 = 0; j1 < mass1.data.GetLength(1); j1++) { if (max<mass1.data[i1,j1]) { max = mass1.data[i1, j1]; } } } max++; for (int i1 = 0; i1 <mass1.data.GetLength(0); i1++) { for (int j1 = 0; j1 < mass1.data.GetLength(1); j1++) { if (j1== j || i1==i) { mass1.data[i1, j1] = max; } } } for (int i1 = 0; i1 < mass2.data.GetLength(0); i1++) { for (int j1 = 0; j1 < mass2.data.GetLength(1); j1++) { if (mass1.data[i1,j1]==max) { double buf = mass1.data[i1, j1]; mass1.data[i1, j1] = mass1.data[i1, j1 + 1]; mass1.data[i1, j1 + 1] = buf; } } } for (int j1 = 0; j1 < mass2.data.GetLength(0); j1++) { for (int i1 = 0; i1 < mass2.data.GetLength(1); i1++) { if (mass1.data[i1, j1] == max) { double buf = mass1.data[i1, j1]; mass1.data[i1, j1] = mass1.data[i1+1, j1]; mass1.data[i1+1, j1] = buf; } } } for (int j1 = 0; j1 < mass2.data.GetLength(0); j1++) { for (int i1 = 0; i1 < mass2.data.GetLength(1); i1++) { mass2.data[i1, j1] = mass1.data[i1, j1]; } } return (mass2); }
//1231212123123123132 public double apr_2x2(arrays mass) { return (mass.data[0, 0] * mass.data[1, 1] - mass.data[0, 1] * mass.data[1, 0]); }
public double apredelitel(arrays mass) { double a = 0; double massMinApr = 0; bool b = false; do { int i = 0; if (mass.data.GetLength(0) > 2 & mass.data.GetLength(1) > 2) { for (int j = 0; j < mass.data.GetLength(1); j++) { double step = i + j; massMinApr = apredelitel(mini(i, j, mass)); a += mass.data[i, j] * Math.Pow(-1, step) * massMinApr; } b = true; } else { b = true; a = apr_2x2(mass); } } while (b != true); return a; }
static void Main(string[] args) { arrays matrix1 = new arrays(0, 0); arrays matrix2 = new arrays(0, 0); arrays matrix3 = new arrays(0, 0); int x; do { Console.WriteLine("1- Creat arrays"); Console.WriteLine("2- Print arrays"); Console.WriteLine("3- + arrays"); Console.WriteLine("4- - arrays"); Console.WriteLine("5- * arrays"); Console.WriteLine("6- / arrays"); Console.WriteLine("7 - ^ arrays"); x = Convert.ToInt16(Console.ReadLine()); switch (x) { case 1://создание и добовление массива { Console.WriteLine("First array"); Console.WriteLine("Row:"); int n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Col:"); int m = Convert.ToInt32(Console.ReadLine()); matrix1 = new arrays(n, m); matrix1.create(); Console.WriteLine("Second array"); Console.WriteLine("Row:"); n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Col:"); m = Convert.ToInt32(Console.ReadLine()); matrix2 = new arrays(n, m); matrix3 = new arrays(m,n); matrix2.create(); break; } case 2://вывод массива { Console.WriteLine(matrix1.print()); Console.WriteLine(); Console.WriteLine(matrix2.print()); Console.WriteLine(); Console.WriteLine(matrix3.print()); Console.ReadLine(); break; } case 3://сложение массивов { matrix3 = matrix1 + matrix2; break; } case 4://вычитание массивов { matrix3 = matrix1 - matrix2; break; } case 5://умножение массивов { matrix3 = matrix1 * matrix2; break; } case 6: { matrix3 = matrix1 / matrix2; break; } case 7: { int n = Convert.ToInt32(Console.ReadLine()); matrix3 = matrix1.exponent(matrix1, n); break; } } Console.Clear(); } while (x != 0); }
public static arrays operator /(arrays mass1, arrays mass2) { arrays buf = new arrays(mass1.data.GetLength(1), mass1.data.GetLength(0)); double a = mass2.apredelitel(mass2); for (int i = 0; i < mass2.data.GetLength(0); i++) { for (int j = 0; j < mass2.data.GetLength(1); j++) { mass2.data[i, j] = (double)(1/a)* mass2.apredelitel(mass2.mini(i, j, mass2)); } } buf = mass1 * mass2; return buf; }
public arrays mini(int i, int j, arrays mass) { int k = 0; double[] s = new double[(mass.data.GetLength(0) - 1) * (mass.data.GetLength(1) - 1)]; arrays mass1 = mass; arrays mass2 = new arrays(mass.data.GetLength(0)-1 , mass.data.GetLength(1)-1); double max = mass.data[0, 0]; for (int i1 = 0; i1 < mass1.data.GetLength(0); i1++) { for (int j1 = 0; j1 < mass1.data.GetLength(1); j1++) { if (i1 !=i) { if (j1 != j) { s[k] += mass1.data[i1, j1]; k++; } } } } k = -1; for (int i1 = 0; i1 < mass2.data.GetLength(0); i1++) { for (int j1 = 0; j1 < mass2.data.GetLength(1); j1++) { k++; mass2.data[i1, j1] = s[k]; } } return (mass2); }