Esempio n. 1
0
 private void factorSVDToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (OutputMatrix != null)
         {
             OutputMatrix.FactorSVD();
             MMatrix U = new MMatrix(OutputMatrix.SVD_U);
             MMatrix S = new MMatrix(OutputMatrix.SVD_S);
             MMatrix Vt = new MMatrix(OutputMatrix.SVD_Vt);
             string s = "\n\n\n";
             s += "Factor SVD:\n";
             s += "\nU=\n" + U.PrintToString();
             s += "\nS=\n" + S.PrintToString();
             s += "\nV'=\n" + Vt.PrintToString();
             //s += "\nA=USV*\n" + (U * S * Vt.Transpose()).PrintToString();
             RichText_Display(s);
         }
     }
     catch (MMatrixException exp)
     {
         MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Esempio n. 2
0
 private void factorLDLtToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (OutputMatrix != null)
         {
             OutputMatrix.FactorLDLt();
             MMatrix L = new MMatrix(OutputMatrix.LDL_L);
             MMatrix D = new MMatrix(OutputMatrix.LDL_D);
             string s = "\n\n\nFactor LDL*:\n";
             s += "\nL=\n" + L.PrintToString();
             s += "\nD=\n" + D.PrintToString();
             s += "\nA=LDL*\n" + (L*D*L.Transpose()).PrintToString();
             RichText_Display(s);
         }
     }
     catch (MMatrixException exp)
     {
         MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Esempio n. 3
0
 private void factorLUToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (OutputMatrix != null)
         {
             OutputMatrix.FactorLU_withP();
             MMatrix P = new MMatrix(OutputMatrix.LU_P);
             MMatrix L = new MMatrix(OutputMatrix.LU_L);
             MMatrix U = new MMatrix(OutputMatrix.LU_U);
             string s = "\n\n\nFactor LU:\n";
             s += "\nP=\n" + P.PrintToString();
             s += "\nL=\n" + L.PrintToString();
             s += "\nU=\n" + U.PrintToString();
             s += "\nA=P*LU\n" + (P.Transpose()*L*U).PrintToString();
             RichText_Display(s);
         }
     }
     catch (MMatrixException exp)
     {
         MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Esempio n. 4
0
 private void eigenvectorsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         StringBuilder sb = new StringBuilder("");
         Vector eigenvalues = new Vector();
         MMatrix eigenvectors = new MMatrix();
         if (OutputMatrix != null)
         {
             MMatrix temp = OutputMatrix.Clone();
             temp.Jacobi_Cyclic_Method(ref eigenvalues, ref eigenvectors);
             sb.Append("\n\n\nEigenvectors (A) = \n");
             for (int i = 0; i < eigenvectors.col; ++i)
             {
                 sb.Append("V");
                 sb.Append(i + 1);
                 sb.Append("\t\t");
             }
             sb.Append("\n");
             sb.Append(eigenvectors.PrintToString());
             RichText_Display(sb.ToString());
         }
     }
     catch (MMatrixException exp)
     {
         MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Esempio n. 5
0
        public void SVDMatrixTest()
        {
            double[,] Arr1 = new double[3, 3] { { 4, -1, 1 }, { -1, 4.25, 2.75 }, { 1, 2.75, 3.5 } };
            double[,] Arr2 = new double[4, 4] { { 1, 1, 0, 3 }, { 2, 1, -1, 1 }, { 3, -1, -1, 2 }, { -1, 2, 3, -1 } };
            double[,] Arr3 = new double[2, 3] { { 3, 1, 1 }, { -1, 3, 1 } };
            double[,] Arr4 = new double[4, 4] { { 3, 1, 0, 1 }, { 1, 3, 1, 1 }, { 0, 1, 3, 1 }, { 1, 1, 1, 3 } };
            MMatrix A = new MMatrix(Arr2);
            MMatrix B = new MMatrix();
            string s = "";

            try
            {
                //A = MMatrix.RandomMatrix(size,0,255);
                A.FactorSVD();

                s = "Factor SVD:\n";
                s += "\nMatrix A=\n" + A.PrintToString();
                s += "\nU=\n" + (new MMatrix(A.SVD_U)).PrintToString();
                s += "\nS=\n" + (new MMatrix(A.SVD_S)).PrintToString();
                s += "\nVt=\n" + (new MMatrix(A.SVD_Vt)).PrintToString();

                B = (new MMatrix(A.SVD_U)) * (new MMatrix(A.SVD_S)) * (new MMatrix(A.SVD_Vt));
                s += "\nA=USV*\n" + B.PrintToString();

                this.RichText_Display(s);
                OutputMatrix = A;
            }
            catch (MMatrixException exp)
            {
                MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 6
0
        public void QRTest()
        {
            double[,] Arr1 = new double[4, 4] { { 4, 1, -2, 2 }, { 1, 2, 0, 1 }, { -2, 0, 3, -2 }, { 2, 1, -2, -1 } };
            double[,] Arr2 = new double[4, 4] { { 3,1,0,1 }, { 1, 3, 1,1 }, {0,1,3,1 },{1,1,1,3} };
            MMatrix A = new MMatrix(Arr2);
            MMatrix B = new MMatrix(Arr2);
            string s = "";

            try
            {

                s += "\nA=\n" + A.PrintToString();

                A.Householder();
                s += "\nHouseholder (A): A(n-1)=\n" + A.PrintToString();
                s += "\nEigenvalues approximation: " + A.Eigenvalues().PrintToString();

                s += "\nEigenvalues: " + B.Eigenvalues().PrintToString();

                this.RichText_Display(s);
            }
            catch (MMatrixException exp)
            {
                MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 7
0
        public void MatrixTest()
        {
            double[,] Arr1 = new double[4, 4] { { 1, 1, 0, 3 }, { 2, 1, -1, 1 }, { 3, -1, -1, 2 }, { -1, 2, 3, -1 } };
            double[,] Arr2 = new double[3, 3] { { 4, -1, 1 }, { -1, 4.25, 2.75 }, { 1, 2.75, 3.5 } };
            MMatrix A = new MMatrix(Arr1);
            MMatrix B = new MMatrix();
            MMatrix C = new MMatrix();
            string s = "";

            try
            {
                //A = MMatrix.RandomMatrix(size,0,10);

                s += "\nMatrix A=\n" + A.PrintToString();
                s += "\nDet (A)=                    \n" + Convert.ToString(A.Determinant()) + "\n";
                s += "\nA^-1=                    \n" + A.Inverse().PrintToString();
                s += "\nA*A^-1=                     \n" + (A * A.Inverse()).PrintToString();
                C = A * A.Transpose();
                s += "\nC=A*A^T=\n" + C.PrintToString();

                /////////////////Factor A = LDL*

                MMatrix.FactorLDLt(C);
                s += "\nFactor LDL*(C): L=\n" + (new MMatrix(C.LDL_L)).PrintToString();
                s += "\nFactor LDL*(C): D=\n" + (new MMatrix(C.LDL_D)).PrintToString();
                B = (new MMatrix(C.LDL_L)) * (new MMatrix(C.LDL_D)) * (new MMatrix(C.LDL_L)).Transpose();
                s += "\nFactor LDL*: C=L*D*L^T\n" + B.PrintToString();
                B = (new MMatrix(C.LDL_L)) * (new MMatrix(C.LDL_L)).Transpose();
                s += "\nFactor LDL*: C=L*L^T\n" + B.PrintToString();

                /////////////////Factor A = LU

                C.FactorLU();
                s += "\nFactor LU(C): L=\n" + (new MMatrix(C.LU_L)).PrintToString();
                s += "\nFactor LU(C): U=\n" + (new MMatrix(C.LU_U)).PrintToString();
                s += "\nFactor LU: C=L*U\n" + ((new MMatrix(C.LU_L)) * (new MMatrix(C.LU_U))).PrintToString();

                ///////////////////Factor A = PLU

                A.FactorLU_withP();
                s += "\nFactor LU (A): P=\n" + (new MMatrix(A.LU_P)).PrintToString();
                s += "\nFactor LU (A): L=\n" + (new MMatrix(A.LU_L)).PrintToString();
                s += "\nFactor LU (A): U=\n" + (new MMatrix(A.LU_U)).PrintToString();
                s += "\nFactor LU: A=PLU\n" + ((new MMatrix(A.LU_P)).Transpose() * (new MMatrix(A.LU_L)) * (new MMatrix(A.LU_U))).PrintToString();

                this.RichText_Display(s);
                OutputMatrix = C;
            }
            catch (MMatrixException exp)
            {
                MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 8
0
        public void EigenvectorTest()
        {
            double[,] Arr1 = new double[4, 4] { { 4, 1, -2, 2 }, { 1, 2, 0, 1 }, { -2, 0, 3, -2 }, { 2, 1, -2, -1 } };
            double[,] Arr2 = new double[2, 3] { { 3,1,1 }, { -1, 3,1 }};
            double[,] Arr3 = new double[5, 5] { { 2, 0, 8, 6, 0 }, { 1, 6, 0, 1, 7 }, { 5, 0, 7, 4, 0 }, { 7, 0, 8, 5, 0 }, { 0, 10, 0, 0, 7 } };
            double[,] Arr4 = new double[4, 4] { { 3, 1, 0, 1 }, { 1, 3, 1, 1 }, { 0, 1, 3, 1 }, { 1, 1, 1, 3 } };
            MMatrix A = new MMatrix(Arr2);
            MMatrix B = new MMatrix();
            string s = "";
            Vector v = new Vector();
            MMatrix Eigenvectors = new MMatrix();

            try
            {
                //A = MMatrix.RandomMatrix(3,0,255);
                B = A*A.Transpose();
                s += "\nAA*=\n" + B.PrintToString();

                B.Jacobi_Cyclic_Method(ref v, ref Eigenvectors);
                s += "\nBefore sort:";
                s += "\nEigenvalues of(A*At)=" + v.PrintToString();
                s += "\nEigenvectors of A*At:\n" + Eigenvectors.PrintToString();

                MMatrix.SortEigen(ref v, ref Eigenvectors);
                s += "\nAfter sort:";
                s += "\nEigenvalues of(A*At)=" + v.PrintToString();
                s += "\nEigenvectors of A*At:\n" + Eigenvectors.PrintToString();

                //This is not neccesary anymore since the eigenvectors are already orthonomalized
                s += "\nOrthonormalize eigenvectors(Ax = 0)\n" + MMatrix.Orthonormalize(Eigenvectors).PrintToString();

                this.RichText_Display(s);
            }
            catch (MMatrixException exp)
            {
                MessageBox.Show("INFO: " + exp.Message, sProjectTile, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }