private void btnGerarDeterminanteM2_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); } } if (tempResultante.GetLength(0) == 2 && tempResultante.GetLength(1) == 2) { determinante = CalculosMatrizes.GerarDeterminante2x2(tempResultante); MessageBox.Show("" + determinante, "Determinante..."); } else if (tempResultante.GetLength(0) == 3 && tempResultante.GetLength(1) == 3) { determinante = CalculosMatrizes.GerarDeterminante3x3(tempResultante); MessageBox.Show("" + determinante, "Determinante..."); } else { MessageBox.Show("Nao e possivel gerar determinante !", "Error - Matriz invalida "); } }
private void btnGerarOpostaM2_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 = CalculosMatrizes.GerarOposta(tempResultante); int TamanhoText = groupBoxMatriz2.Width / Matriz2.GetLength(1); for (int x = 0; x < Matriz2.GetLength(0); x++) { for (int y = 0; y < Matriz2.GetLength(1); y++) { Matriz2[x, y].Text = tempMatrizResultante[x, y].ToString(); } } }
private void btnGerarDeterminante_Click(object sender, EventArgs e) { if (MatrizR == null) { MessageBox.Show("Matriz nula !", "Error - Matriz"); return; } float[,] tempResultante = new float[MatrizR.GetLength(0), MatrizR.GetLength(1)]; for (int x = 0; x < MatrizR.GetLength(0); x++) { for (int y = 0; y < MatrizR.GetLength(1); y++) { float n = 0; float.TryParse(MatrizR[x, y].Text, out n); tempResultante[x, y] = n; } } if (tempResultante.GetLength(0) == 2 && tempResultante.GetLength(1) == 2) { determinante = CalculosMatrizes.GerarDeterminante2x2(tempResultante); MessageBox.Show("" + determinante, "Determinante..."); } else if (tempResultante.GetLength(0) == 3 && tempResultante.GetLength(1) == 3) { determinante = CalculosMatrizes.GerarDeterminante3x3(tempResultante); MessageBox.Show("" + determinante, "Determinante..."); } else { MessageBox.Show("O determinante é o próprio elemento da matriz !", "Propriedade"); } }
private void btnMultiplicar_Click(object sender, EventArgs e) { if (Matriz1 == null || Matriz2 == null) { MessageBox.Show("Matriz nula !", "Error - Matriz"); return; } float[,] tempMatriz1 = new float[Matriz1.GetLength(0), Matriz1.GetLength(1)]; float[,] tempMatriz2 = new float[Matriz2.GetLength(0), Matriz2.GetLength(1)]; if (tempMatriz1.GetLength(1) != tempMatriz2.GetLength(0)) { MessageBox.Show("So e possivel a multiplicacao de matrizes onde a coluna da matriz 1 e igual a linha da matriz 2 !", "Erro - Multiplicacao Matrizes"); return; } for (int x = 0; x < Matriz1.GetLength(0); x++) { for (int y = 0; y < Matriz1.GetLength(1); y++) { float n = 0; float.TryParse(Matriz1[x, y].Text, out n); tempMatriz1[x, y] = n; //tempMatriz1[x, y] = Convert.ToInt32(Matriz1[x, y].Text); } } 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; //tempMatriz2[x, y] = Convert.ToInt32(Matriz2[x, y].Text); } } float[,] tempMatrizResultante = CalculosMatrizes.MultiplicarMatrizes(tempMatriz1, tempMatriz2); MatrizResultante = new TextBox[tempMatrizResultante.GetLength(0), tempMatrizResultante.GetLength(1)]; int TamanhoText = groupBoxMatrizResultante.Width / MatrizResultante.GetLength(1); groupBoxMatrizResultante.Controls.Clear(); for (int x = 0; x < MatrizResultante.GetLength(0); x++) { for (int y = 0; y < MatrizResultante.GetLength(1); y++) { MatrizResultante[x, y] = new TextBox(); MatrizResultante[x, y].Text = tempMatrizResultante[x, y].ToString(); MatrizResultante[x, y].Top = (x * MatrizResultante[x, y].Height) + 20; MatrizResultante[x, y].Left = y * TamanhoText + 6; MatrizResultante[x, y].Width = TamanhoText; groupBoxMatrizResultante.Controls.Add(MatrizResultante[x, y]); } } }
private void btnSomar_Click(object sender, EventArgs e) { if (MatrizA == null || MatrizB == null) { MessageBox.Show("Matriz nula !", "Error - Matriz"); return; } float[,] tempMatriz1 = new float[MatrizA.GetLength(0), MatrizA.GetLength(1)]; float[,] tempMatriz2 = new float[MatrizB.GetLength(0), MatrizB.GetLength(1)]; if (tempMatriz1.GetLength(0) != tempMatriz2.GetLength(0) || tempMatriz1.GetLength(1) != tempMatriz2.GetLength(1)) { MessageBox.Show("So e possivel a soma de matrizes de mesma ordem !", "Erro - Soma Matrizes"); return; } for (int x = 0; x < MatrizA.GetLength(0); x++) { for (int y = 0; y < MatrizA.GetLength(1); y++) { float n = 0; float.TryParse(MatrizA[x, y].Text, out n); tempMatriz1[x, y] = n; } } for (int x = 0; x < MatrizB.GetLength(0); x++) { for (int y = 0; y < MatrizB.GetLength(1); y++) { float n = 0; float.TryParse(MatrizB[x, y].Text, out n); tempMatriz2[x, y] = n; } } float[,] tempMatrizR = CalculosMatrizes.SomarMatrizes(tempMatriz1, tempMatriz2); MatrizR = new TextBox[tempMatrizR.GetLength(0), tempMatrizR.GetLength(1)]; int TamanhoText = groupBoxMatrizResultante.Width / MatrizR.GetLength(1); groupBoxMatrizResultante.Controls.Clear(); for (int x = 0; x < MatrizR.GetLength(0); x++) { for (int y = 0; y < MatrizR.GetLength(1); y++) { MatrizR[x, y] = new TextBox(); MatrizR[x, y].Text = tempMatrizR[x, y].ToString(); MatrizR[x, y].Top = (x * MatrizR[x, y].Height) + 20; MatrizR[x, y].Left = y * TamanhoText + 6; MatrizR[x, y].Width = TamanhoText; groupBoxMatrizResultante.Controls.Add(MatrizR[x, y]); } } }
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 = CalculosMatrizes.GerarTransposta(tempResultante); int TamanhoText = groupBoxMatriz2.Width / Matriz2.GetLength(1); 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 + 6; Matriz2[x, y].Width = TamanhoText; groupBoxMatriz2.Controls.Add(Matriz2[x, y]); } } }
private void btnGerarInversaM2_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)]; float[,] matrizAdjunta = new float[Matriz2.GetLength(0), Matriz2.GetLength(1)]; float[,] matrizCofatora = new float[Matriz2.GetLength(0), Matriz2.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 < 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); } } /*Matriz Adjunta(A) = Matriz Transposta(Matriz dos cofatores(A)) * Matriz Inversa(A) = (1/ Determinante(A)) * Matriz Adjunta(A)*/ if (tempResultante.GetLength(0) == 2 && tempResultante.GetLength(1) == 2) { matrizCofatora = CalculosMatrizes.GerarCofatora2x2(tempResultante); matrizAdjunta = CalculosMatrizes.GerarTransposta(matrizCofatora); determinante = CalculosMatrizes.GerarDeterminante2x2(tempResultante); } else if (tempResultante.GetLength(0) == 3 && tempResultante.GetLength(1) == 3) { matrizCofatora = CalculosMatrizes.GerarCofatora3x3(tempResultante); matrizAdjunta = CalculosMatrizes.GerarTransposta(matrizCofatora); determinante = CalculosMatrizes.GerarDeterminante3x3(tempResultante); } else { MessageBox.Show("Matriz invalida !", "Error - Matriz"); return; } if (determinante == 0) { MessageBox.Show("Matriz invalida, determinante igual a 0 !", "Error - Matriz"); return; } float[,] tempMatrizResultante = CalculosMatrizes.GerarInversa(determinante, matrizAdjunta); int TamanhoText = groupBoxMatriz2.Width / Matriz2.GetLength(1); for (int x = 0; x < Matriz2.GetLength(0); x++) { for (int y = 0; y < Matriz2.GetLength(1); y++) { Matriz2[x, y].Text = tempMatrizResultante[x, y].ToString(); } } }