Пример #1
0
        public new IntegerSquareMatrix GetTransposed()
        {
            IntegerSquareMatrix matrix = new IntegerSquareMatrix(Rows);

            Transpose(matrix);
            return(matrix);
        }
Пример #2
0
        private void CreateClick()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string path = dialog.FileName;


                Arithmetics.Matrix.IntegerSquareMatrix graphMatrix = (IntegerSquareMatrix)IntegerMatrix.GetFromFile(path);
                if (graphMatrix.Columns == 0)
                {
                    return;
                }
                string name = Interaction.InputBox("Введите имя графа", "", "");
                if (graphs.ContainsKey(name) == false)
                {
                    Graph NewGraph = new Graph(graphMatrix);
                    graphs.Add(name, NewGraph);
                    activeGraph       = name;
                    richTextBox1.Text = "";
                    richTextBox1.Text = graphs[activeGraph].ToString();
                    graphsToolStripMenuItem.DropDownItems.Add(name);

                    DialogResult result = MessageBox.Show("Граф " + name + " успешно добавлен");
                }
                else
                {
                    DialogResult result = MessageBox.Show("Граф c таким именем уже существует");
                }
            }
        }
Пример #3
0
        public IntegerSquareMatrix AddColomnsAndRows(int[] new_colomns, int[] new_rows)
        {
            int[,] newElements = new int[Rows + 1, Columns + 1];
            for (int i = 0; i < Rows + 1; i++)
            {
                for (int j = 0; j < Columns + 1; j++)
                {
                    if ((j != Rows) && (i != Columns))
                    {
                        newElements[i, j] = elements[i, j];
                    }
                    else
                    {
                        if ((j == Rows) && (i != Columns))
                        {
                            newElements[i, j] = new_colomns[i];
                        }
                        else
                        {
                            if ((j != Rows) && (i == Columns))
                            {
                                newElements[i, j] = new_rows[j];
                            }
                            else
                            {
                                newElements[i, j] = new_colomns[i] + new_rows[j];
                            }
                        }
                    }
                }
            }
            IntegerSquareMatrix matrix = new IntegerSquareMatrix(Rows + 1, newElements);

            return(matrix);
        }
Пример #4
0
 /// <summary>
 /// Аналог GetFromFile в <see cref="IntegerMatrix"/>
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static Graph GetFromFile(string path)
 {
     Arithmetics.Matrix.IntegerSquareMatrix graphMatrix = (IntegerSquareMatrix)IntegerMatrix.GetFromFile(path);
     if (graphMatrix.Columns == 0)
     {
         return(null);
     }
     return(new Graph(graphMatrix));
 }
Пример #5
0
        /// <summary>
        /// Returns an Identity <paramref name="n"/> × <paramref name="n"/> matrix.
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static IntegerSquareMatrix GetE(int n)
        {
            IntegerSquareMatrix E = new IntegerSquareMatrix(n);

            for (int k = 0; k < n; k++)
            {
                E[k, k] = 1;
            }
            return(E);
        }
Пример #6
0
        public IntegerSquareMatrix AdditionOfLines(int summline, int termline)
        {
            IntegerSquareMatrix newMatrix = new IntegerSquareMatrix(Rows, elements);

            for (int i = 0; i < Rows; i++)
            {
                newMatrix[summline, i] += newMatrix[termline, i];
            }
            return(newMatrix);
        }
Пример #7
0
        public IntegerSquareMatrix SubtractionOfLines(int reducedLine, int deductibleline)
        {
            IntegerSquareMatrix newMatrix = new IntegerSquareMatrix(Rows, elements);

            for (int i = 0; i < Rows; i++)
            {
                newMatrix[reducedLine, i] -= newMatrix[deductibleline, i];
            }
            return(newMatrix);
        }
Пример #8
0
        public int DetMod(int prime_number)
        {
            IntegerSquareMatrix triangleMatrix = new IntegerSquareMatrix(Rows, elements);
            int signOfDet = 0;

            for (int i = 0; i < triangleMatrix.Rows; i++)
            {
                for (int j = i; j < triangleMatrix.Columns; j++)
                {
                    if (triangleMatrix[j, i] != 0)
                    {
                        int reverselement = NumberFunctions.GetMulInverse(triangleMatrix[j, i], prime_number);
                        for (int k = j; k < triangleMatrix.Columns; k++)
                        {
                            triangleMatrix[j, k] *= reverselement;
                            triangleMatrix[j, k] %= prime_number;
                        }
                        if (i != j)
                        {
                            triangleMatrix = triangleMatrix.SwapLine(j, i);
                            signOfDet++;
                            signOfDet %= 2;                                            //ОПРЕДЕЛЯЮ ЗНАК det
                        }
                        for (int k = j + 1; k < triangleMatrix.Columns; k++)
                        {
                            while (triangleMatrix[k, j] != 0)
                            {
                                if (triangleMatrix[k, j] > 0)
                                {
                                    triangleMatrix = triangleMatrix.SubtractionOfLines(k, j);
                                }
                                else
                                {
                                    triangleMatrix = triangleMatrix.AdditionOfLines(k, j);
                                }
                            }
                        }
                    }
                }
            }
            int det = 1;

            for (int i = 0; i < triangleMatrix.Columns; i++)
            {
                det *= triangleMatrix[i, i];
            }
            if (signOfDet == 0)
            {
                return(det);
            }
            else
            {
                return(-1 * det);
            }
        }
Пример #9
0
        public IntegerSquareMatrix SwapLine(int line1, int line2)
        {
            IntegerSquareMatrix newMatrix = new IntegerSquareMatrix(Rows, elements);
            int temp;

            for (int i = 0; i < Rows; i++)
            {
                temp = newMatrix[line1, i];
                newMatrix[line1, i] = newMatrix[line2, i];
                newMatrix[line2, i] = temp;
            }
            return(newMatrix);
        }
Пример #10
0
        /// <summary>
        /// Repeated Squaring algorithm for <paramref name="deg"/> power of the matrix modulo <paramref name="mod"/>
        /// </summary>
        /// <param name="deg"></param>
        /// <param name="mod"></param>
        /// <returns></returns>
        public IntegerSquareMatrix ModPow(long deg, int mod)
        {
            IntegerSquareMatrix Result  = GetE(Columns);
            IntegerSquareMatrix Squared = new IntegerSquareMatrix(this);

            while (deg > 0)
            {
                if (deg % 2 == 1)
                {
                    Result = (Result * Squared) % mod;
                }
                Squared = (Squared * Squared) % mod;
                deg    /= 2;
            }
            return(Result);
        }
Пример #11
0
        public IntegerSquareMatrix ConvertToIntegerSquareMatrix()
        {
            if (this.Rows != this.Columns)
            {
                return(null);
            }
            IntegerSquareMatrix matrix = new IntegerSquareMatrix(this.Columns);

            for (int i = 0; i < this.Rows; i++)
            {
                for (int j = 0; j < this.Columns; j++)
                {
                    matrix[i, j] = this[i, j];
                }
            }

            return(matrix);
        }
Пример #12
0
        public IntegerSquareMatrix ToTopTriangleMatrixModPrime(int primeNumber, int degree)
        {
            IntegerSquareMatrix triangleMatrix = new IntegerSquareMatrix(Rows, elements);
            int sign_of_det  = 0;
            int primeNumber1 = Convert.ToInt32(Math.Pow(primeNumber, degree));

            for (int i = 0; i < triangleMatrix.Rows; i++)
            {
                for (int j = i; j < triangleMatrix.Columns; j++)
                {
                    if (triangleMatrix[j, i] != 0)
                    {
                        int reverselement = NumberFunctions.GetMulInverse(triangleMatrix[j, i], primeNumber1);
                        for (int k = j; k < triangleMatrix.Columns; k++)
                        {
                            triangleMatrix[j, k] *= reverselement;
                            triangleMatrix[j, k] %= primeNumber1;
                        }
                        if (i != j)
                        {
                            triangleMatrix = triangleMatrix.SwapLine(j, i);
                            sign_of_det++;
                            sign_of_det %= 2;                                            //ОПРЕДЕЛЯЮ ЗНАК det
                        }
                        for (int k = j + 1; k < triangleMatrix.Columns; k++)
                        {
                            while (triangleMatrix[k, j] != 0)
                            {
                                if (triangleMatrix[k, j] > 0)
                                {
                                    triangleMatrix = triangleMatrix.SubtractionOfLines(k, j);
                                }
                                else
                                {
                                    triangleMatrix = triangleMatrix.AdditionOfLines(k, j);
                                }
                            }
                        }
                    }
                }
            }
            return(triangleMatrix);
        }
Пример #13
0
 public IntegerSquareMatrix(IntegerSquareMatrix matrix) : base(matrix)
 {
 }