Exemplo n.º 1
0
        /// <summary>
        /// Logic after click button (search invert matrix)
        /// </summary>
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            ClearGrid(resultGrid);

            if (infofile.Text == "File does not upload")
            {
                ReadMatrixFromContGrid();
            }

            if (matrix != null)
            {
                double[,] copyMatrix = MatrixOp.CopyMatrix(matrix);
                if (Determinate.IsZero(copyMatrix))
                {
                    MessageBox.Show("Determinate is zero");
                    return;
                }
            }
            else
            {
                return;
            }

            inversionMatrix = new double[matrix.GetLength(0), matrix.GetLength(0)];

            if (Methods.SelectedIndex == 0)
            {
                inversionMatrix = InversionEdging.Inversion(matrix);
            }
            else if (Methods.SelectedIndex == 1)
            {
                inversionMatrix = InversionLU.Inversion(matrix);

                if (inversionMatrix == null)
                {
                    MessageBox.Show("Try another method", "Matrix not decomposition method LU");
                    return;
                }
            }
            else if (Methods.SelectedIndex == 2)
            {
                inversionMatrix = InversionLU.Inversion(matrix);

                if (inversionMatrix == null)
                {
                    inversionMatrix = InversionLUP.Inversion(matrix);
                }
            }

            if (inversionMatrix != null && inversionMatrix.GetLength(0) <= 10)
            {
                InitGridValue(resultGrid, inversionMatrix);
                ResultMatrix.Text = "Result Matrix";
            }
            else if (inversionMatrix != null && inversionMatrix.GetLength(0) > 10)
            {
                SaveOnExecuted(null, null);
            }

            infofile.Text       = "File does not upload";
            infofile.Foreground = Brushes.Red;
            if (inversionMatrix != null)
            {
                inforesult.Text       = "Successfully";
                inforesult.Foreground =
                    new SolidColorBrush(Color.FromRgb((byte)r.Next(1, 255), (byte)r.Next(1, 255), (byte)r.Next(1, 233)));
                MessageBox.Show("Successfully");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Inversion matrix method LUP
 /// </summary>
 public static double[,] Inversion(double[,] matrix)
 {
     double[,] P = GetMatrixPermutation(matrix);
     (double[,] L, double[,] U) = InversionLU.Decomposition(MatrixOp.Multiply(P, matrix));
     return(InversionLU.DecisionSystem(matrix, P, L, U));
 }