Ejemplo n.º 1
0
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////
        /// </summary>

        private void buttonSubtract_Click(object sender, EventArgs e)
        {
            try
            {
                if (RowA != RowB || ColA != ColB)
                {
                    MyMessageBox.Show("Không thể trừ hai ma trận khác kích thước");
                }
                else
                {
                    GlobalsMatrix.tru();
                    Add_MatrixRe(RowA, ColA);
                    GlobalsMatrix.setRowMatrixRe(RowA);
                    GlobalsMatrix.setColMatrixRe(ColA);
                    RowR = GlobalsMatrix.RowRe;
                    ColR = GlobalsMatrix.ColRe;
                    if (RowR >= 5 && ColR >= 5)
                    {
                        flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
                    }
                    else
                    {
                        flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
                    }
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void buttonInputFileB_Click(object sender, EventArgs e)
        {
            try
            {
                GlobalsMatrix.docketqua("B");

                if (GlobalsMatrix.RowB > 50 || GlobalsMatrix.ColB > 50)
                {
                    RowB       = GlobalsMatrix.RowB;
                    ColB       = GlobalsMatrix.RowB;
                    MatrixName = "B";
                    MyMessageBox.Show("Đã thêm ma trận B, do ma trận có kích thước lớn vui lòng nhập số dòng/cột rồi nhấn nút show để xem chi tiết");
                    textBoxColB.Text = "" + GlobalsMatrix.ColB;
                    textBoxRowB.Text = "" + GlobalsMatrix.RowB;
                }
                else
                {
                    MyMessageBox.Show("Dòng hoặc cột nhỏ hơn hoặc bằng 50, vui lòng sử dụng chức năng Matrix's smaller than 50x50");
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void buttonMultiply_Click(object sender, EventArgs e)
 {
     try
     {
         if (ColA != RowB)
         {
             MyMessageBox.Show("Không thỏa điều kiện thực hiện phép nhân");
         }
         else
         {
             GlobalsMatrix.nhan();
             Add_MatrixRe(RowA, ColB);
             GlobalsMatrix.setRowMatrixRe(RowA);
             GlobalsMatrix.setColMatrixRe(ColB);
             RowR = GlobalsMatrix.RowRe;
             ColR = GlobalsMatrix.ColRe;
             if (RowR >= 5 && ColR >= 5)
             {
                 flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
             }
             else
             {
                 flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 4
0
 private void buttonOutputFileB_Click(object sender, EventArgs e)
 {
     try
     {
         GlobalsMatrix.ghiketqua(GlobalsMatrix.B, GlobalsMatrix.RowB, GlobalsMatrix.ColB);
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 5
0
 private void buttonSavetoFile_Click(object sender, EventArgs e)
 {
     try
     {
         GlobalsMatrix.ghiketqua(GlobalsMatrix.Re, GlobalsMatrix.RowRe, GlobalsMatrix.ColRe);
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 6
0
 private void buttonInputFileB_Click(object sender, EventArgs e)
 {
     try
     {
         GlobalsMatrix.docketqua("B");
         if (GlobalsMatrix.RowB <= 50 && GlobalsMatrix.ColB <= 50)
         {
             //Nếu Ma Trận chưa được khởi tạo -> Tạo mới Ma Trận
             if (RowB == 0 && ColB == 0)
             {
                 RowB       = GlobalsMatrix.RowB;
                 ColB       = GlobalsMatrix.RowB;
                 MatrixName = "B";
                 Add_MatrixRead();
                 textBoxColB.Text = "" + GlobalsMatrix.ColB;
                 textBoxRowB.Text = "" + GlobalsMatrix.RowB;
             }
             //Nếu muốn tạo ra ma trận ngẫu nhiên khác
             else
             if (GlobalsMatrix.RowB == RowB && GlobalsMatrix.ColB == ColB)
             {
                 MatrixName = "B";
                 RowB       = GlobalsMatrix.RowB;
                 ColB       = GlobalsMatrix.RowB;
                 Refresh_MatrixRead();
                 textBoxColB.Text = "" + GlobalsMatrix.ColB;
                 textBoxRowB.Text = "" + GlobalsMatrix.RowB;
             }
             //Trường hợp còn lại
             else
             {
                 MatrixName = "B";
                 Delete_MatrixRead();
                 RowB = GlobalsMatrix.RowB;
                 ColB = GlobalsMatrix.RowB;
                 Add_MatrixRead();
                 textBoxColB.Text = "" + GlobalsMatrix.ColB;
                 textBoxRowB.Text = "" + GlobalsMatrix.RowB;
             }
         }
         else
         {
             MyMessageBox.Show("Dòng hoặc cột lớn hơn 50, vui lòng sử dụng chức năng Matrix's bigger than 50x50");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 7
0
 private void buttonInverseB_Click(object sender, EventArgs e)
 {
     try
     {
         if (GlobalsMatrix.RowB <= 30 && GlobalsMatrix.ColB <= 30)
         {
             if ((GlobalsMatrix.DetM(GlobalsMatrix.B, GlobalsMatrix.RowB) == 0) || (GlobalsMatrix.RowB != GlobalsMatrix.ColB))
             {
                 MyMessageBox.Show("Không thể thực hiện đảo ma trận B");
             }
             else
             {
                 MatrixName = "B";
                 InverseMatrix inversefrm = new InverseMatrix(MatrixName);
                 inversefrm.Show();
                 MatrixName = "R";
                 Delete_Matrix();
                 Add_MatrixRe(ColB, RowB);
                 GlobalsMatrix.setRowMatrixRe(ColB);
                 GlobalsMatrix.setColMatrixRe(RowB);
                 RowR = GlobalsMatrix.RowRe;
                 ColR = GlobalsMatrix.ColRe;
             }
         }
         else
         {
             if ((GlobalsMatrix.DetM(GlobalsMatrix.B, GlobalsMatrix.RowB) == 0) || (GlobalsMatrix.RowB != GlobalsMatrix.ColB))
             {
                 MyMessageBox.Show("Không thể thực hiện đảo ma trận B");
             }
             else
             {
                 MatrixName = "B";
                 InverseMatrix inversefrm = new InverseMatrix(MatrixName);
                 inversefrm.MergeMatrixBig(GlobalsMatrix.B, GlobalsMatrix.RowB);
                 MatrixName = "R";
                 Delete_Matrix();
                 Add_MatrixRe(ColB, RowB);
                 GlobalsMatrix.setRowMatrixRe(ColB);
                 GlobalsMatrix.setColMatrixRe(RowB);
                 RowR = GlobalsMatrix.RowRe;
                 ColR = GlobalsMatrix.ColRe;
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 8
0
 private void buttonTransposeB_Click(object sender, EventArgs e)
 {
     try
     {
         GlobalsMatrix.chuyenvi(GlobalsMatrix.RowB, GlobalsMatrix.ColB, GlobalsMatrix.B);
         GlobalsMatrix.setRowMatrixRe(RowB);
         GlobalsMatrix.setColMatrixRe(ColB);
         MyMessageBox.Show("Đã chuyển vị ma trận B");
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 9
0
 private void buttonClearResult_Click(object sender, EventArgs e)
 {
     try
     {
         MatrixName = "Re";
         Delete_Matrix();
         GlobalsMatrix.setRowMatrixRe(0);
         GlobalsMatrix.setColMatrixRe(0);
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 10
0
 private void buttonClearB_Click(object sender, EventArgs e)
 {
     try
     {
         MatrixName = "B";
         Delete_Matrix();
         GlobalsMatrix.setRowMatrixB(0);
         GlobalsMatrix.setColMatrixB(0);
         textBoxColB.Text = "";
         textBoxRowB.Text = "";
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 11
0
 private void buttonGetRandomA_Click(object sender, EventArgs e)
 {
     try
     {
         if (int.Parse(textBoxRowA.Text) <= 50 && int.Parse(textBoxColA.Text) <= 50)
         {
             //Nếu Ma Trận chưa được khởi tạo -> Tạo mới Ma Trận
             if (RowA == 0 && ColA == 0)
             {
                 RowA = int.Parse(textBoxRowA.Text);
                 ColA = int.Parse(textBoxColA.Text);
                 GlobalsMatrix.setRowMatrixA(int.Parse(textBoxRowA.Text));
                 GlobalsMatrix.setColMatrixA(int.Parse(textBoxColA.Text));
                 MatrixName = "A";
                 Add_Matrix();
             }
             //Nếu muốn tạo ra ma trận ngẫu nhiên khác
             else
             if (GlobalsMatrix.RowA == int.Parse(textBoxRowA.Text) && GlobalsMatrix.ColA == int.Parse(textBoxColA.Text))
             {
                 MatrixName = "A";
                 Refresh_Matrix();
             }
             //Trường hợp còn lại
             else
             {
                 MatrixName = "A";
                 Delete_Matrix();
                 GlobalsMatrix.setRowMatrixA(int.Parse(textBoxRowA.Text));
                 GlobalsMatrix.setColMatrixA(int.Parse(textBoxColA.Text));
                 RowA = int.Parse(textBoxRowA.Text);
                 ColA = int.Parse(textBoxColA.Text);
                 Add_Matrix();
             }
         }
         else
         {
             MyMessageBox.Show("Dòng hoặc cột lớn hơn 50, vui lòng sử dụng chức năng Matrix's bigger than 50x50");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 12
0
 private void buttonMultiply_Click(object sender, EventArgs e)
 {
     try
     {
         if (ColA != RowB)
         {
             MyMessageBox.Show("Không thỏa điều kiện thực hiện phép nhân");
         }
         else
         {
             GlobalsMatrix.nhan();
             GlobalsMatrix.setRowMatrixRe(RowA);
             GlobalsMatrix.setColMatrixRe(ColB);
             MyMessageBox.Show("Đã nhân hai ma trận");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 13
0
 private void buttonSubtract_Click(object sender, EventArgs e)
 {
     try
     {
         if (RowA != RowB || ColA != ColB)
         {
             MyMessageBox.Show("Không thể trừ hai ma trận khác kích thước");
         }
         else
         {
             GlobalsMatrix.tru();
             GlobalsMatrix.setRowMatrixRe(RowA);
             GlobalsMatrix.setColMatrixRe(ColA);
             MyMessageBox.Show("Đã trừ hai ma trận");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 14
0
 public void btnChange_Click(object sender, EventArgs e)
 {
     try
     {
         float num = float.Parse(textBox1.Text);
         if (MatrixName == "A")
         {
             GlobalsMatrix.setMatrixA(Col, Row, num);
         }
         else
         if (MatrixName == "B")
         {
             GlobalsMatrix.setMatrixB(Col, Row, num);
         }
         Small.num = num;
         this.Close();
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////
        /// </summary>
        private void Add_MatrixBig()
        {
            try
            {
                Random rd = new Random();
                if (MatrixName == "A")
                {
                    Col = GlobalsMatrix.ColA;
                    Row = GlobalsMatrix.RowA;
                }
                else
                if (MatrixName == "B")
                {
                    Col = GlobalsMatrix.ColB;
                    Row = GlobalsMatrix.RowB;
                }
                for (int i = 0; i < Row; i++)
                {
                    for (int j = 0; j < Col; j++)
                    {
                        float t = rd.Next(0, 100);

                        if (MatrixName == "A")
                        {
                            GlobalsMatrix.setMatrixA(i, j, t);
                        }
                        else
                        if (MatrixName == "B")
                        {
                            GlobalsMatrix.setMatrixB(i, j, t);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 16
0
 private void buttonInverseA_Click(object sender, EventArgs e)
 {
     try
     {
         if ((GlobalsMatrix.DetM(GlobalsMatrix.A, GlobalsMatrix.RowA) != 0) && (GlobalsMatrix.RowA == GlobalsMatrix.ColA))
         {
             MatrixName = "A";
             InverseMatrix inversefrm = new InverseMatrix();
             inversefrm.MergeMatrixBig(GlobalsMatrix.A, GlobalsMatrix.RowA);
             GlobalsMatrix.setRowMatrixRe(ColA);
             GlobalsMatrix.setColMatrixRe(RowA);
             MyMessageBox.Show("Đã đảo ma trận A");
         }
         else
         {
             MyMessageBox.Show("Không thể thực hiện đảo ma trận A");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void buttonTransposeB_Click(object sender, EventArgs e)
 {
     try
     {
         GlobalsMatrix.chuyenvi(GlobalsMatrix.RowB, GlobalsMatrix.ColB, GlobalsMatrix.B);
         Add_MatrixRe(ColB, RowB);
         GlobalsMatrix.setRowMatrixRe(ColB);
         GlobalsMatrix.setColMatrixRe(RowB);
         RowR = GlobalsMatrix.RowRe;
         ColR = GlobalsMatrix.ColRe;
         if (RowR >= 5 && ColR >= 5)
         {
             flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
         }
         else
         {
             flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 18
0
 private void buttonGetRandomB_Click(object sender, EventArgs e)
 {
     try
     {
         if (int.Parse(textBoxRowB.Text) > 50 || int.Parse(textBoxColB.Text) > 50)
         {
             RowB = int.Parse(textBoxRowB.Text);
             ColB = int.Parse(textBoxColB.Text);
             GlobalsMatrix.setRowMatrixB(int.Parse(textBoxRowB.Text));
             GlobalsMatrix.setColMatrixB(int.Parse(textBoxColB.Text));
             MatrixName = "B";
             Add_MatrixBig();
             MyMessageBox.Show("Đã tạo ma trận B ngẫu nhiên, do ma trận có kích thước lớn vui lòng nhập số dòng/cột rồi nhấn nút show để xem chi tiết");
         }
         else
         {
             MyMessageBox.Show("Dòng hoặc cột nhỏ hơn hoặc bằng 50, vui lòng sử dụng chức năng Matrix's smaller than 50x50");
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 19
0
        /////////////////////////////////////////////////////////////////////
        ///Doc xuat file
        public static void docketqua(string MatrixName)
        {
            string         s = "";
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"C:\",
                Title            = "Browse Text Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "txt",
                Filter           = "txt files (*.txt)|*.txt",
                FilterIndex      = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                s = openFileDialog1.FileName;
            }
            if (s != "")
            {
                if (MatrixName == "A")
                {
                    GlobalsMatrix.setRowMatrixA(0);
                    GlobalsMatrix.setColMatrixA(0);
                    String input = File.ReadAllText(s);
                    int    i = 0, j = 0;
                    foreach (var row in input.Split('\n'))
                    {
                        j = 0;
                        foreach (string col in row.Trim().Split(' '))
                        {
                            float t = float.Parse(col.Trim());
                            GlobalsMatrix.setMatrixA(i, j, t);
                            j++;
                        }
                        i++;
                    }
                    GlobalsMatrix.setRowMatrixA(i);
                    GlobalsMatrix.setColMatrixA(j);
                }
                else if (MatrixName == "B")
                {
                    GlobalsMatrix.setRowMatrixB(0);
                    GlobalsMatrix.setColMatrixB(0);
                    String input = File.ReadAllText(s);
                    int    i = 0, j = 0;
                    foreach (var row in input.Split('\n'))
                    {
                        j = 0;
                        foreach (string col in row.Trim().Split(' '))
                        {
                            float t = float.Parse(col.Trim());
                            GlobalsMatrix.setMatrixB(i, j, t);
                            j++;
                        }
                        i++;
                    }
                    GlobalsMatrix.setRowMatrixB(i);
                    GlobalsMatrix.setColMatrixB(j);
                }
                else
                {
                    MyMessageBox.Show("Ma trận không hợp lệ");
                }
            }
            else
            {
                MyMessageBox.Show("Bạn chưa chọn file");
            }
        }
Ejemplo n.º 20
0
        public void MergeMatrixBig(float[,] A, int RowCol)
        {
            //Buoc Giai A^-1
            CreatedMatrixI(RowCol);
            for (int i = 0; i < RowCol; i++)
            {
                for (int j = 0; j < RowCol; j++)
                {
                    C[i, j] = A[i, j];
                }
            }
            for (int i = 0; i < RowCol; i++)
            {
                for (int j = 0; j < RowCol; j++)
                {
                    C[i, j + RowCol] = mI[i, j];
                }
            }
            //Add_MatrixRe(RowCol, RowCol * 2, 1);
            // Xuat(C, 8);

            //Buoc 2 Giai A^-1
            //Xuat(C, RowCol);

            for (int i = 0; i < RowCol - 1; i++)
            {
                int nho = i;
                for (int x = i; x < RowCol; x++)
                {
                    if (C[x, i] != 0)
                    {
                        nho = x;
                        break;
                    }
                }
                if (nho != i)
                {
                    for (int j = i; j < RowCol; j++)
                    {
                        C[i, j] += C[nho, j];
                    }
                    C[i, nho + RowCol] += 1;
                }

                for (int t = 1; t < RowCol - i; t++)
                {
                    float k = C[i + t, i] / C[i, i];
                    for (int j = i; j < RowCol * 2; j++)
                    {
                        C[i + t, j] = C[i + t, j] - k * C[i, j];
                    }
                }
            }
            //Add_MatrixRe(RowCol, RowCol * 2, 2);
            //Xuat(C, RowCol);

            //Buoc 3
            for (int i = 0; i < RowCol; i++)
            {
                float k = 1 / C[i, i];
                for (int j = i; j < RowCol * 2; j++)
                {
                    C[i, j] *= k;
                }
            }

            //Buoc RowCol
            for (int i = RowCol - 1; i > 0; i--)
            {
                for (int k = i - 1; k >= 0; k--)
                {
                    float x = C[k, i];
                    for (int j = i; j < RowCol * 2; j++)
                    {
                        C[k, j] -= (x * C[i, j]);
                    }
                }
            }
            //Add_MatrixRe(RowCol, RowCol * 2, 3);

            for (int i = 0; i < RowCol; i++)
            {
                for (int j = RowCol; j < RowCol * 2; j++)
                {
                    GlobalsMatrix.setMatrixRe(i, j - RowCol, C[i, j]);
                }
                ;
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void Delete_Matrix()
 {
     try
     {
         if (MatrixName == "A")
         {
             Col = GlobalsMatrix.ColA;
             Row = GlobalsMatrix.RowA;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelA.Controls.Remove(pan);
                     }
                 }
             }
             GlobalsMatrix.setColMatrixA(0);
             GlobalsMatrix.setRowMatrixA(0);
         }
         else
         if (MatrixName == "B")
         {
             Col = GlobalsMatrix.ColB;
             Row = GlobalsMatrix.RowB;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelB.Controls.Remove(pan);
                     }
                 }
             }
             GlobalsMatrix.setColMatrixB(0);
             GlobalsMatrix.setRowMatrixB(0);
         }
         else
         if (MatrixName == "Re")
         {
             Col = GlobalsMatrix.ColRe;
             Row = GlobalsMatrix.RowRe;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelR.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     pan.Controls.Remove(btn);
                                 }
                             }
                         }
                         flowLayoutPanelR.Controls.Remove(pan);
                     }
                 }
             }
             GlobalsMatrix.setColMatrixRe(0);
             GlobalsMatrix.setRowMatrixRe(0);
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 22
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void Refresh_Matrix()
 {
     try
     {
         Random rd = new Random();
         if (MatrixName == "A")
         {
             Col = GlobalsMatrix.ColA;
             Row = GlobalsMatrix.RowA;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelA.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     float t = rd.Next(0, 100);
                                     btn.Text = "" + t;
                                     if (MatrixName == "A")
                                     {
                                         GlobalsMatrix.setMatrixA(i, j, t);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else
         if (MatrixName == "B")
         {
             Col = GlobalsMatrix.ColB;
             Row = GlobalsMatrix.RowB;
             for (int i = 0; i < Row; i++)
             {
                 foreach (FlowLayoutPanel pan in flowLayoutPanelB.Controls.OfType <FlowLayoutPanel>())
                 {
                     if ((MatrixName + i) == pan.Name)
                     {
                         foreach (Button btn in pan.Controls.OfType <Button>())
                         {
                             for (int j = 0; j < Col; j++)
                             {
                                 if ((MatrixName + i + "_" + j) == btn.Name)
                                 {
                                     float t = rd.Next(0, 100);
                                     btn.Text = "" + t;
                                     if (MatrixName == "B")
                                     {
                                         GlobalsMatrix.setMatrixB(i, j, t);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 23
0
        /// </summary>
        private void Add_Matrix()
        {
            try
            {
                Random rd = new Random();
                if (MatrixName == "A")
                {
                    Col = GlobalsMatrix.ColA;
                    Row = GlobalsMatrix.RowA;
                }
                else
                if (MatrixName == "B")
                {
                    Col = GlobalsMatrix.ColB;
                    Row = GlobalsMatrix.RowB;
                }
                for (int i = 0; i < Row; i++)
                {
                    FlowLayoutPanel pan = new FlowLayoutPanel();
                    pan.Name      = MatrixName + i;
                    pan.BackColor = Color.Violet;
                    pan.Size      = new System.Drawing.Size(46 * Col, 43);
                    for (int j = 0; j < Col; j++)
                    {
                        Button btn = new Button();
                        btn.Name = MatrixName + i + "_" + j;
                        float t = rd.Next(0, 100);
                        btn.Text = "" + t;

                        if (MatrixName == "A")
                        {
                            GlobalsMatrix.setMatrixA(i, j, t);
                        }
                        else
                        if (MatrixName == "B")
                        {
                            GlobalsMatrix.setMatrixB(i, j, t);
                        }
                        else
                        {
                            btn.Text = btn.Name;
                        }
                        btn.Size   = new System.Drawing.Size(40, 40);
                        btn.Click += btn_Click;
                        pan.Controls.Add(btn);
                    }
                    pan.FlowDirection = FlowDirection.LeftToRight;
                    if (MatrixName == "A")
                    {
                        flowLayoutPanelA.Controls.Add(pan);
                    }
                    else
                    if (MatrixName == "B")
                    {
                        flowLayoutPanelB.Controls.Add(pan);
                    }

                    if (GlobalsMatrix.ColA >= 5 && GlobalsMatrix.RowA >= 5)
                    {
                        flowLayoutPanelA.FlowDirection = FlowDirection.LeftToRight;
                    }
                    else
                    {
                        flowLayoutPanelA.FlowDirection = FlowDirection.TopDown;
                    }


                    if (GlobalsMatrix.ColB >= 5 && GlobalsMatrix.RowB >= 5)
                    {
                        flowLayoutPanelB.FlowDirection = FlowDirection.LeftToRight;
                    }
                    else
                    {
                        flowLayoutPanelB.FlowDirection = FlowDirection.TopDown;
                    }
                }
            }
            catch (Exception ex)
            {
                MyMessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 24
0
 /// <summary>
 /// //////////////////////////////////////////////////////////////////////////////
 /// </summary>
 private void buttonInverseA_Click(object sender, EventArgs e)
 {
     try
     {
         if (GlobalsMatrix.RowA <= 30 && GlobalsMatrix.ColA <= 30)
         {
             if ((GlobalsMatrix.DetM(GlobalsMatrix.A, GlobalsMatrix.RowA) != 0) && (GlobalsMatrix.RowA == GlobalsMatrix.ColA))
             {
                 MatrixName = "A";
                 InverseMatrix inversefrm = new InverseMatrix();
                 inversefrm.Show();
                 MatrixName = "R";
                 Delete_Matrix();
                 Add_MatrixRe(ColA, RowA);
                 GlobalsMatrix.setRowMatrixRe(ColA);
                 GlobalsMatrix.setColMatrixRe(RowA);
                 RowR = GlobalsMatrix.RowRe;
                 ColR = GlobalsMatrix.ColRe;
                 if (RowR >= 5 && ColR >= 5)
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
                 }
                 else
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
                 }
             }
             else
             {
                 MyMessageBox.Show("Không thể thực hiện đảo ma trận A");
             }
         }
         else
         {
             if ((GlobalsMatrix.DetM(GlobalsMatrix.A, GlobalsMatrix.RowA) != 0) && (GlobalsMatrix.RowA == GlobalsMatrix.ColA))
             {
                 MatrixName = "A";
                 InverseMatrix inversefrm = new InverseMatrix();
                 inversefrm.MergeMatrixBig(GlobalsMatrix.A, GlobalsMatrix.RowA);
                 MatrixName = "R";
                 Delete_Matrix();
                 Add_MatrixRe(ColA, RowA);
                 GlobalsMatrix.setRowMatrixRe(ColA);
                 GlobalsMatrix.setColMatrixRe(RowA);
                 RowR = GlobalsMatrix.RowRe;
                 ColR = GlobalsMatrix.ColRe;
                 if (RowR >= 5 && ColR >= 5)
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.LeftToRight;
                 }
                 else
                 {
                     flowLayoutPanelR.FlowDirection = FlowDirection.TopDown;
                 }
             }
             else
             {
                 MyMessageBox.Show("Không thể thực hiện đảo ma trận A");
             }
         }
     }
     catch (Exception ex)
     {
         MyMessageBox.Show(ex.Message);
     }
 }