//From now on, our comments will use latex syntax
        public static int Test_ElementaryMatrix_Multiply_ElementaryMatrix()
        {
            /*
             *  E_{ij}E_{rs} = e_ie'_je_re'_s = \delta_{r j}e'_ie'_s = \delta_{j r}E_{is} \\
             *  if\;r = j \\
             *  E_{ij}E_{rs} = \delta_{j j}E_{is} = E_{is}
             *
             */
            StringBuilder    sb  = new StringBuilder();
            ElementaryMatrix E12 = new ElementaryMatrix(4, 4, "E13"); // 4 x 4 ElementaryMatrix
            ElementaryMatrix E13 = new ElementaryMatrix(4, 4, "E32"); // 4 x 4 ElementaryMatrix

            sb.Append(@"E_{ij}E_{rs} = e_ie'_je_re'_s = \delta_{r j}e'_ie'_s = \delta_{j r}E_{is} \\");
            sb.Append(@"if\;r = j \\");
            sb.Append(@"E_{ij}E_{rs} = \delta_{j j}E_{is} = E_{is} \\");
            sb.Append(@"Output\;is: \\");
            //Test Elementary Matrix * Elementary Matrix

            ElementaryMatrix em = E12 * E13;

            sb.Append(em.ToLatex("F"));

            HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(sb.ToString(), "Test_ElementaryMatrix_Multiply_ElementaryMatrix.html"); //display Latex via mathjax

            return(0);
        }
        public static int Test_ElementaryMatrix_ElementaryMatrix()
        {
            ElementaryMatrix em = new ElementaryMatrix(4, 4, "E11");

            HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(em.ToLatex("F"), "Test_ElementaryMatrix_ElementaryMatrix.html");

            return(0);
        }
        public static int Test_UnitVectorProductTo_ElementaryMatrix()
        {
            UnitVectorSpace  uvs = new UnitVectorSpace(4);                                                                    //Order four Unit Vector Space
            UnitVector       e2  = uvs["e2"];                                                                                 // order 4 e2 unit vector
            UnitVector       e1  = uvs["e1"];                                                                                 //order 4 e1 unit operator
            ElementaryMatrix em  = e2 * e1;                                                                                   //product of Unit Vectors

            HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(em.ToLatex("F"), "Test_UnitVectorProductTo_ElementaryMatrix.html"); //display Latex via mathjax

            return(0);
        }
Esempio n. 4
0
        /*TODO: remove this GPG
         * public static UnitVector operator*(ElementaryMatrix em, UnitVector uv)
         * {
         *  UnitVector uvOut = null;
         *  //using following realtionships
         *  //Eij * er = ei * e'j * er
         *  // = &jr * ei where & is the Kronecker Delta
         *  UnitVectorSpace uvp = new UnitVectorSpace(uv.Order);
         *  UnitVector ei = uvp["e" + em.Major.ToString()];
         *  UnitVector ej = uvp["e" + em.Minor.ToString()];
         *  RowColumn rc = ej.IsRowOrColumn;
         *  ej.IsRowOrColumn = RowColumn.Row;
         *
         *  uvOut = ei * ej * uv;
         *  ej.IsRowOrColumn = rc; //Set it back to what it was
         *  return uvOut;
         * }
         */

        public static ElementaryMatrix operator*(UnitVector e1, UnitVector e2)
        {
            ElementaryMatrix em = null;
            RowColumn        rc = e2.IsRowOrColumn;


            if (e1.IsRowOrColumn == RowColumn.Row) //Dot product
            {
                return((ElementaryMatrix)DotProduct(e1, e2));
            }


            e2.IsRowOrColumn = RowColumn.Row; //transpose

            string emName = "E" + e1.Name[1].ToString() + e2.Name[1].ToString();

            em         = new ElementaryMatrix(e1.Order, e2.Order, emName);
            em.FullRep = em.LatexName + " = " + e1.ToLatex() + e2.ToLatex() + " = " + em.ToLatex();

            e2.IsRowOrColumn = rc; //set back to what it was
            return(em);
        }
        public static ElementaryMatrix operator *(ElementaryMatrix a, ElementaryMatrix b)
        {
            ElementaryMatrix retVal = new ElementaryMatrix(a.Rows, a.Columns);

            for (int rowCount = 0; rowCount < retVal.Rows; rowCount++)
            {
                for (int colCount = 0; colCount < retVal.Columns; colCount++)
                {
                    for (int k = 0; k < retVal.Columns; k++)
                    {
                        retVal.InternalRep[rowCount, colCount] += a.InternalRep[rowCount, k] * b.InternalRep[k, colCount];

                        if (retVal.InternalRep[rowCount, colCount] == 1)
                        {
                            retVal.Major       = rowCount + 1;
                            retVal.Minor       = colCount + 1;
                            retVal.Name        = $"E{retVal.Major.ToString()}{retVal.Minor.ToString()}";
                            retVal.m_LatexName = $"E_{{{(retVal.Major).ToString() + (retVal.Minor).ToString()}}}";
                        }
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(a.LatexName + b.LatexName + " = ");
            sb.Append(a.ToLatex());
            sb.Append(b.ToLatex());
            sb.Append(" = ");
            sb.Append(retVal.LatexName + " = ");
            sb.Append(retVal.ToLatex());

            retVal.FullRep = sb.ToString();

            return(retVal);
        }
        public static int Test_UnitVector_Multiply_ElementaryMatrix()
        {
            /*
             * e'r * Eij = e'r * ei * e'j = &ri *e'j where & = Kronecker delta
             *
             */
            StringBuilder    sb  = new StringBuilder();
            ElementaryMatrix E12 = new ElementaryMatrix(4, 4, "E12");      // 4 x 4 ElementaryMatrix
            UnitVector       e1  = new UnitVector("e1", 4);                //Order four unit vector e1
            UnitVector       e2  = new UnitVector("e2", 4, RowColumn.Row); //Order four row unit vector e2
            UnitVector       er  = new UnitVector("e3", 4, RowColumn.Row); //Order four unit row vector e3 our er above

            /*
             * i = 1, j = 2, r = 3
             */

            sb.Append(@"e'_rE_{ij} = e'_re_ie'_j = \delta_{r j}e'j \\");
            //Test matrix unit vector * Elementary Matrix,  er * Eij
            UnitVector uvE1 = er * E12;

            sb.Append(@"e'_3E_{12} = " + uvE1.ToLatex() + @"\;");

            //Test e'r * ei * e'j
            UnitVector uvE2 = er * e1 * e2;

            sb.Append(@"e'_3e_1e'_2 = " + uvE2.ToLatex() + @"\;");

            //Test &ri * e'j
            UnitVector uvE3 = UnitVector.KroneckerDelta(3, 1) * e2;

            sb.Append(@" \delta_{3 1}e_2 = " + uvE3.ToLatex() + @" \tag{1}");

            HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(sb.ToString(), "Test_UnitVector_Multiply_ElementaryMatrix.html"); //display Latex via mathjax

            return(0);
        }
        public static int Test_ElementaryMatrix_Multiply_UnitVector()
        {
            /*
             * Eij * er = ei*e'j*er = &jr *ei where & = Kronecker delta
             *
             */
            StringBuilder    sb  = new StringBuilder();
            ElementaryMatrix E12 = new ElementaryMatrix(4, 4, "E12");      // 4 x 4 ElementaryMatrix
            UnitVector       e1  = new UnitVector("e1", 4);                //Order four unit vector e1
            UnitVector       e2  = new UnitVector("e2", 4, RowColumn.Row); //Order four row unit vector e2
            UnitVector       er  = new UnitVector("e3", 4);                //Order four unit vector e3 our er above

            /*
             * i = 1, j = 2, r = 3
             */

            //Test matrix * unit vector, Eij * er
            UnitVector uvE1 = E12 * er;

            sb.Append(@"E_{12}e_3 = " + uvE1.ToLatex() + @"\;");

            //Test e1* e'j * er
            UnitVector uvE2 = e1 * e2 * er;

            sb.Append(@"e_1e'_2e_3 = " + uvE2.ToLatex() + @"\;");

            //Test &jr * ei
            UnitVector uvE3 = UnitVector.KroneckerDelta(2, 3) * e1;

            sb.Append(@" \delta_{2 3}e_1 = " + uvE3.ToLatex());

            HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(sb.ToString(), "Test_ElementaryMatrix_Multiply_UnitVector.html"); //display Latex via mathjax


            return(0);
        }