Exemple #1
0
        private void btnGerarTranspostM2_Click(object sender, EventArgs e)
        {
            if (Matriz2 == null)
            {
                MessageBox.Show("Matriz nula !", "Error - Matriz");
                return;
            }
            float[,] tempResultante = 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);
                    tempResultante[x, y] = n;
                    //tempResultante[x, y] = Convert.ToInt32(Matriz2[x, y].Text);
                }
            }

            float[,] tempMatrizResultante = Calculos.GerarTransposta(tempResultante);
            int TamanhoText = groupBox2.Width / Matriz2.GetLength(1);

            Matriz2 = new TextBox[tempMatrizResultante.GetLength(0), tempMatrizResultante.GetLength(1)];
            groupBox2.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 + 6;
                    Matriz2[x, y].Width = TamanhoText;
                    groupBox2.Controls.Add(Matriz2[x, y]);
                }
            }
        }
Exemple #2
0
        private void Transposta_Click(object sender, EventArgs e)
        {
            if (matrizResultado == null)
            {
                MessageBox.Show("Matriz nula !", "Error - Matriz");
                return;
            }
            float[,] tempResultante = new float[matrizResultado.GetLength(0), matrizResultado.GetLength(1)];

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

            float[,] tempMatrizResultante = Calculos.GerarTransposta(tempResultante);
            int TamanhoText = groupBoxResultado.Width / matrizResultado.GetLength(1);

            matrizResultado = new TextBox[tempMatrizResultante.GetLength(0), tempMatrizResultante.GetLength(1)];
            groupBoxResultado.Controls.Clear();
            for (int x = 0; x < matrizResultado.GetLength(0); x++)
            {
                for (int y = 0; y < matrizResultado.GetLength(1); y++)
                {
                    matrizResultado[x, y]       = new TextBox();
                    matrizResultado[x, y].Text  = tempMatrizResultante[x, y].ToString();
                    matrizResultado[x, y].Top   = (x * matrizResultado[x, y].Height) + 20;
                    matrizResultado[x, y].Left  = y * TamanhoText + 6;
                    matrizResultado[x, y].Width = TamanhoText;
                    groupBoxResultado.Controls.Add(matrizResultado[x, y]);
                }
            }
        }
Exemple #3
0
        private void btnGerarInversa_Click(object sender, EventArgs e)
        {
            if (matrizResultado == null)
            {
                MessageBox.Show("Matriz nula !", "Error - Matriz");
                return;
            }
            float[,] tempResultante = new float[matrizResultado.GetLength(0), matrizResultado.GetLength(1)];
            float[,] matrizAdjunta  = new float[matrizResultado.GetLength(0), matrizResultado.GetLength(1)];
            float[,] matrizCofatora = new float[matrizResultado.GetLength(0), matrizResultado.GetLength(1)];
            float determinante = 0;

            if (tempResultante.GetLength(0) != 2 || tempResultante.GetLength(1) != 2)
            {
                if (tempResultante.GetLength(0) != 3 || tempResultante.GetLength(1) != 3)
                {
                    MessageBox.Show("Matriz invalida !", "Error - Matriz");
                    return;
                }
            }

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

            if (tempResultante.GetLength(0) == 2 && tempResultante.GetLength(1) == 2)
            {
                matrizCofatora = Calculos.GerarCofatora2x2(tempResultante);
                matrizAdjunta  = Calculos.GerarTransposta(matrizCofatora);
                determinante   = Calculos.GerarDeterminante2x2(tempResultante);
            }
            else if (tempResultante.GetLength(0) == 3 && tempResultante.GetLength(1) == 3)
            {
                matrizCofatora = Calculos.GerarCofatora3x3(tempResultante);
                matrizAdjunta  = Calculos.GerarTransposta(matrizCofatora);
                determinante   = Calculos.GerarDeterminante3x3(tempResultante);
            }
            else
            {
                MessageBox.Show("Matriz invalida 2!", "Error - Matriz");
                return;
            }
            if (determinante == 0)
            {
                MessageBox.Show("Matriz invalida, determinante igual a 0 !", "Error - Matriz");
                return;
            }
            float[,] tempMatrizResultante = Calculos.GerarInversa(determinante, matrizAdjunta);
            int TamanhoText = groupBoxResultado.Width / matrizResultado.GetLength(1);

            for (int x = 0; x < matrizResultado.GetLength(0); x++)
            {
                for (int y = 0; y < matrizResultado.GetLength(1); y++)
                {
                    matrizResultado[x, y].Text = tempMatrizResultante[x, y].ToString();
                }
            }
        }