Beispiel #1
0
        private void MatrizInversa2_Click(object sender, EventArgs e)
        {
            if (Matriz2 == null)
            {
                MessageBox.Show("Matriz nula!", "Error - Matriz");
                return;
            }

            if (Matriz2.GetLength(0) != Matriz2.GetLength(1))
            {
                MessageBox.Show("Atenção!\n\nSó é possível calcular o determinante de matrizes quadradas", "Error - Matriz Inversa");
                return;
            }

            float[,] tempMatriz2 = new float[Matriz2.GetLength(0), Matriz2.GetLength(1)];

            for (int x = 0; x < Matriz2.GetLength(0); x++)
            {
                for (int y = 0; y < Matriz2.GetLength(1); y++)
                {
                    float n = 0;
                    float.TryParse(Matriz2[x, y].Text, out n);
                    tempMatriz2[x, y] = n;
                }
            }

            if ((CalculosMatrizes.Determinante(tempMatriz2)) == 0)
            {
                MessageBox.Show("Atenção!\n\nSó é possível calcular a inversa de matrizes\ncujo o determinante é diferente de zero.", "Error - Matriz Inversa");
                return;
            }

            float[,] tempMatrizResultante = CalculosMatrizes.Inversa(tempMatriz2);
            int TamanhoText = groupBoxMatriz2.Width / Matriz2.GetLength(0);

            Matriz2 = new TextBox[tempMatrizResultante.GetLength(0), tempMatrizResultante.GetLength(1)];
            groupBoxMatriz2.Controls.Clear();

            for (int x = 0; x < Matriz2.GetLength(0); x++)
            {
                for (int y = 0; y < Matriz2.GetLength(1); y++)
                {
                    Matriz2[x, y]       = new TextBox();
                    Matriz2[x, y].Text  = tempMatrizResultante[x, y].ToString();
                    Matriz2[x, y].Top   = (x * Matriz2[x, y].Height) + 20;
                    Matriz2[x, y].Left  = y * TamanhoText + 1;
                    Matriz2[x, y].Width = TamanhoText;
                    groupBoxMatriz2.Controls.Add(Matriz2[x, y]);
                }
            }
        }
Beispiel #2
0
        private void DeterminanteMatriz2_Click(object sender, EventArgs e)
        {
            if (Matriz2 == null)
            {
                MessageBox.Show("Matriz nula!", "Error - Matriz");
                return;
            }

            if (Matriz2.GetLength(0) != Matriz2.GetLength(1))
            {
                MessageBox.Show("Atenção!\n\nSó é possível calcular o determinante de matrizes quadradas", "Error - Determinante da Matriz");
                return;
            }

            float[,] tempMatriz2 = new float[Matriz2.GetLength(0), Matriz2.GetLength(1)];

            for (int x = 0; x < Matriz2.GetLength(0); x++)
            {
                for (int y = 0; y < Matriz2.GetLength(1); y++)
                {
                    float n = 0;
                    float.TryParse(Matriz2[x, y].Text, out n);
                    tempMatriz2[x, y] = n;
                }
            }

            float determinante = -1111111;

            if (tempMatriz2.GetLength(0) == 1)
            {
                determinante = tempMatriz2[0, 0];
            }
            else
            {
                determinante = CalculosMatrizes.Determinante(tempMatriz2);
            }

            Determinante2.Text = "det = " + determinante.ToString();
        }