private void button1_Click(object sender, EventArgs e)
        {
            if (text1_3_0.Text == "" || text1_3_1.Text == "" || text1_3_2.Text == "" || text1_3_3.Text == "" || text1_3_4.Text == "" || text1_3_5.Text == "" || text1_3_6.Text == "" || text1_3_7.Text == "" || text1_3_8.Text == "" || text3_0.Text == "" || text3_1.Text == "" || text3_2.Text == "" || text3_3.Text == "" || text3_4.Text == "" || text3_5.Text == "" || text3_6.Text == "" || text3_7.Text == "" || text3_8.Text == "")
            {
                MessageBox.Show("Please Enter Both The Metrices Correctly.");
            }

            else
            {
                //decimal[,] data1 ={ decimal.Parse(text3_0.Text), decimal.Parse(text3_1.Text), decimal.Parse(text3_2.Text), decimal.Parse(text3_3.Text), decimal.Parse(text3_4.Text), decimal.Parse(text3_5.Text), decimal.Parse(text3_6.Text), decimal.Parse(text3_7.Text), decimal.Parse(text3_8.Text) };
                //decimal[,] data2 ={ decimal.Parse(text1_3_0.Text ), decimal.Parse(text1_3_1.Text ), decimal.Parse(text1_3_2.Text), decimal.Parse(text1_3_3.Text), decimal.Parse(text1_3_4.Text), decimal.Parse(text1_3_5.Text), decimal.Parse(text1_3_6.Text), decimal.Parse(text1_3_7.Text), decimal.Parse(text1_3_8.Text) };
                decimal[,] data1 = new decimal[3, 3];

                decimal[,] data2 = new decimal[3, 3];


                data1[0, 0] = decimal.Parse(text3_0.Text);
                data1[0, 1] = decimal.Parse(text3_1.Text);
                data1[0, 2] = decimal.Parse(text3_2.Text);
                data1[1, 0] = decimal.Parse(text3_3.Text);
                data1[1, 1] = decimal.Parse(text3_4.Text);
                data1[1, 2] = decimal.Parse(text3_5.Text);
                data1[2, 0] = decimal.Parse(text3_6.Text);
                data1[2, 1] = decimal.Parse(text3_7.Text);
                data1[2, 2] = decimal.Parse(text3_8.Text);


                data2[0, 0] = decimal.Parse(text1_3_0.Text);
                data2[0, 1] = decimal.Parse(text1_3_1.Text);
                data2[0, 2] = decimal.Parse(text1_3_2.Text);
                data2[1, 0] = decimal.Parse(text1_3_3.Text);
                data2[1, 1] = decimal.Parse(text1_3_4.Text);
                data2[1, 2] = decimal.Parse(text1_3_5.Text);
                data2[2, 0] = decimal.Parse(text1_3_6.Text);
                data2[2, 1] = decimal.Parse(text1_3_7.Text);
                data2[2, 2] = decimal.Parse(text1_3_8.Text);



                //list1 = new NuGenMatrix(3, 3, data1);


                //list2 = new NuGenMatrix(3, 3, data2);

                list1 = new NuGenMatrix(data1);
                list2 = new NuGenMatrix(data2);



                mat_add.Enabled     = true;
                mat_div.Enabled     = true;
                mat_equ.Enabled     = true;
                mat_mult.Enabled    = true;
                mat_not_equ.Enabled = true;
                mat_sub.Enabled     = true;
            }
        }
Beispiel #2
0
        public static NuGenMatrix ScaleMultiply(decimal scalar, NuGenMatrix M)
        {
            decimal[,] A = M.Data;
            int ro = A.GetLength(0);
            int co = A.GetLength(1);

            decimal[,] B = new decimal[ro, co];

            for (int p = 0; p < ro; p++)
            {
                for (int q = 0; q < co; q++)
                {
                    B[p, q] = scalar * A[p, q];
                }
            }
            return(new NuGenMatrix(B));
        }
Beispiel #3
0
        public static NuGenMatrix RowSwitch(NuGenMatrix M, int i, int j)
        {
            NuGenMatrix MS = NuGenMatrix.DeepCopy(M);

            decimal[,] a = MS.Data;
            int     ro   = a.GetLength(0);
            int     co   = a.GetLength(1);
            decimal temp = 0;

            for (int q = 0; q < co; q++)
            {
                temp    = a[i, q];
                a[i, q] = a[j, q];
                a[j, q] = temp;
            }
            return(new NuGenMatrix(a));
        }
Beispiel #4
0
 public static NuGenMatrix DeepCopy(NuGenMatrix M)
 {
     return ScaleMultiply(1, M);
 }
Beispiel #5
0
        public static NuGenMatrix ScaleMultiply(decimal scalar, NuGenMatrix M)
        {
            decimal[,] A = M.Data;
            int ro = A.GetLength(0);
            int co = A.GetLength(1);
            decimal[,] B = new decimal[ro, co];

            for (int p = 0; p < ro; p++)
            {

                for (int q = 0; q < co; q++)
                {
                    B[p, q] = scalar * A[p, q];
                }
            }
            return (new NuGenMatrix(B));
        }
Beispiel #6
0
        public static NuGenMatrix RowSwitch(NuGenMatrix M, int i, int j)
        {
            NuGenMatrix MS = NuGenMatrix.DeepCopy(M);
            decimal[,] a = MS.Data;
            int ro = a.GetLength(0);
            int co = a.GetLength(1);
            decimal temp = 0;

            for (int q = 0; q < co; q++)
            {
                temp = a[i, q];
                a[i, q] = a[j, q];
                a[j, q] = temp;
            }
            return (new NuGenMatrix(a));
        }
Beispiel #7
0
        /*

        public void display()
        {
            int r1 = this.Data.GetLength(0);int c1 = this.Data.GetLength(1);

            for (int i=0;i<r1;i++)
            {

                for (int j=0;j<c1;j++)
                {
                    Console.Write(this.Data[i,j].ToString("N2")+"   " );				
                }
                Console.WriteLine(); 
            }
            Console.WriteLine(); 
        }
        */

        public static NuGenMatrix INV(NuGenMatrix M)
        {
            decimal[,] a = M.Data;
            int ro = a.GetLength(0);
            int co = a.GetLength(1);

            if (ro != co)
            {
                throw new System.ArgumentException("Cannot find inverse for an non square matrix!");
            }

            int q; decimal[,] b = new decimal[ro, co]; decimal[,] I = Identity(ro).Data;

            for (int p = 0; p < ro; p++) { for (q = 0; q < co; q++) { b[p, q] = a[p, q]; } }
            int i; decimal det = 1;

            if (a[0, 0] == 0)
            {
                i = 1;

                while (i < ro)
                {

                    if (a[i, 0] != 0)
                    {
                        NuGenMatrix.interrow(a, 0, i);
                        NuGenMatrix.interrow(I, 0, i);
                        det *= -1;
                        break;
                    }
                    i++;
                }
            }
            det *= a[0, 0];
            NuGenMatrix.rowdiv(I, 0, a[0, 0]);
            NuGenMatrix.rowdiv(a, 0, a[0, 0]);

            for (int p = 1; p < ro; p++)
            {
                q = 0;

                while (q < p)
                {
                    NuGenMatrix.rowsub(I, p, q, a[p, q]);
                    NuGenMatrix.rowsub(a, p, q, a[p, q]);
                    q++;
                }

                if (a[p, p] != 0)
                {
                    det *= a[p, p];
                    NuGenMatrix.rowdiv(I, p, a[p, p]);
                    NuGenMatrix.rowdiv(a, p, a[p, p]);
                }

                if (a[p, p] == 0)
                {

                    for (int j = p + 1; j < co; j++)
                    {

                        if (a[p, j] != 0)
                        {
                            throw new System.Exception("Unable to determine the Inverse!");
                        }
                    }

                }
            }

            for (int p = ro - 1; p > 0; p--)
            {

                for (q = p - 1; q >= 0; q--)
                {
                    NuGenMatrix.rowsub(I, q, p, a[q, p]);
                    NuGenMatrix.rowsub(a, q, p, a[q, p]);
                }
            }

            for (int p = 0; p < ro; p++)
            {

                for (q = 0; q < co; q++)
                {
                    a[p, q] = b[p, q];
                }
            }

            return (new NuGenMatrix(I));
        }
        private void button1_Click(object sender, EventArgs e)
        {


            if (text1_3_0.Text == "" || text1_3_1.Text == "" || text1_3_2.Text == "" || text1_3_3.Text == "" || text1_3_4.Text == "" || text1_3_5.Text == "" || text1_3_6.Text == "" || text1_3_7.Text == "" || text1_3_8.Text == "" || text3_0.Text == "" || text3_1.Text == "" || text3_2.Text == "" || text3_3.Text == "" || text3_4.Text == "" || text3_5.Text == "" || text3_6.Text == "" || text3_7.Text == "" || text3_8.Text == "")
            {
                MessageBox.Show("Please Enter Both The Metrices Correctly.");
            }

            else
            {

                //decimal[,] data1 ={ decimal.Parse(text3_0.Text), decimal.Parse(text3_1.Text), decimal.Parse(text3_2.Text), decimal.Parse(text3_3.Text), decimal.Parse(text3_4.Text), decimal.Parse(text3_5.Text), decimal.Parse(text3_6.Text), decimal.Parse(text3_7.Text), decimal.Parse(text3_8.Text) };
                //decimal[,] data2 ={ decimal.Parse(text1_3_0.Text ), decimal.Parse(text1_3_1.Text ), decimal.Parse(text1_3_2.Text), decimal.Parse(text1_3_3.Text), decimal.Parse(text1_3_4.Text), decimal.Parse(text1_3_5.Text), decimal.Parse(text1_3_6.Text), decimal.Parse(text1_3_7.Text), decimal.Parse(text1_3_8.Text) };
                decimal[,] data1=new decimal[3,3];

                decimal[,] data2 = new decimal[3, 3];


                data1[0, 0] = decimal.Parse(text3_0.Text);
                data1[0, 1]=decimal.Parse(text3_1.Text);
                data1[0, 2]=decimal.Parse(text3_2.Text);
                data1[1, 0]=decimal.Parse(text3_3.Text);
                data1[1, 1]=decimal.Parse(text3_4.Text);
                data1[1, 2]=decimal.Parse(text3_5.Text);
                data1[2, 0]=decimal.Parse(text3_6.Text);
                data1[2, 1] = decimal.Parse(text3_7.Text);
                data1[2, 2] = decimal.Parse(text3_8.Text);


                data2[0, 0] = decimal.Parse(text1_3_0.Text);
                data2[0, 1] = decimal.Parse(text1_3_1.Text);
                data2[0, 2] = decimal.Parse(text1_3_2.Text);
                data2[1, 0] = decimal.Parse(text1_3_3.Text);
                data2[1, 1] = decimal.Parse(text1_3_4.Text);
                data2[1, 2] = decimal.Parse(text1_3_5.Text);
                data2[2, 0] = decimal.Parse(text1_3_6.Text);
                data2[2, 1] = decimal.Parse(text1_3_7.Text);
                data2[2, 2] = decimal.Parse(text1_3_8.Text);





                //list1 = new NuGenMatrix(3, 3, data1);


                //list2 = new NuGenMatrix(3, 3, data2);

                list1 = new NuGenMatrix(data1);
                list2 = new NuGenMatrix(data2);



                mat_add.Enabled = true;
                mat_div.Enabled = true;
                mat_equ.Enabled = true;
                mat_mult.Enabled = true;
                mat_not_equ.Enabled = true;
                mat_sub.Enabled = true;

            }

        }
Beispiel #9
0
 public static NuGenMatrix DeepCopy(NuGenMatrix M)
 {
     return(ScaleMultiply(1, M));
 }
Beispiel #10
0
        /*
         *
         * public void display()
         * {
         *  int r1 = this.Data.GetLength(0);int c1 = this.Data.GetLength(1);
         *
         *  for (int i=0;i<r1;i++)
         *  {
         *
         *      for (int j=0;j<c1;j++)
         *      {
         *          Console.Write(this.Data[i,j].ToString("N2")+"   " );
         *      }
         *      Console.WriteLine();
         *  }
         *  Console.WriteLine();
         * }
         */

        public static NuGenMatrix INV(NuGenMatrix M)
        {
            decimal[,] a = M.Data;
            int ro = a.GetLength(0);
            int co = a.GetLength(1);

            if (ro != co)
            {
                throw new System.ArgumentException("Cannot find inverse for an non square matrix!");
            }

            int q; decimal[,] b = new decimal[ro, co]; decimal[,] I = Identity(ro).Data;

            for (int p = 0; p < ro; p++)
            {
                for (q = 0; q < co; q++)
                {
                    b[p, q] = a[p, q];
                }
            }
            int i; decimal det = 1;

            if (a[0, 0] == 0)
            {
                i = 1;

                while (i < ro)
                {
                    if (a[i, 0] != 0)
                    {
                        NuGenMatrix.interrow(a, 0, i);
                        NuGenMatrix.interrow(I, 0, i);
                        det *= -1;
                        break;
                    }
                    i++;
                }
            }
            det *= a[0, 0];
            NuGenMatrix.rowdiv(I, 0, a[0, 0]);
            NuGenMatrix.rowdiv(a, 0, a[0, 0]);

            for (int p = 1; p < ro; p++)
            {
                q = 0;

                while (q < p)
                {
                    NuGenMatrix.rowsub(I, p, q, a[p, q]);
                    NuGenMatrix.rowsub(a, p, q, a[p, q]);
                    q++;
                }

                if (a[p, p] != 0)
                {
                    det *= a[p, p];
                    NuGenMatrix.rowdiv(I, p, a[p, p]);
                    NuGenMatrix.rowdiv(a, p, a[p, p]);
                }

                if (a[p, p] == 0)
                {
                    for (int j = p + 1; j < co; j++)
                    {
                        if (a[p, j] != 0)
                        {
                            throw new System.Exception("Unable to determine the Inverse!");
                        }
                    }
                }
            }

            for (int p = ro - 1; p > 0; p--)
            {
                for (q = p - 1; q >= 0; q--)
                {
                    NuGenMatrix.rowsub(I, q, p, a[q, p]);
                    NuGenMatrix.rowsub(a, q, p, a[q, p]);
                }
            }

            for (int p = 0; p < ro; p++)
            {
                for (q = 0; q < co; q++)
                {
                    a[p, q] = b[p, q];
                }
            }

            return(new NuGenMatrix(I));
        }
Beispiel #11
0
 public static NuGenMatrix operator /(decimal D, NuGenMatrix M)
 {
     return(ScaleMultiply(D, NuGenMatrix.INV(M)));
 }