public static int Test_CramersRule()
        {
            RationalFactory      rf    = new RationalFactory(); //Create rational factory
            RationalSquareMatrix ACopy = rf[3, 3,               //Matrix to solve
                                            "1", "2", "-2",
                                            "-1", "1", "3",
                                            "2", "-1", "2"
                                         ];

            RationalVector rv = new RationalVector {
                -7, 3, 8
            };                                      //values to solve for
            StringBuilder sb = new StringBuilder(); //Start building latex

            sb.Append(@"\begin{aligned}");

            //Start system of linear equations
            sb.AppendFormat(@"&x_1 + 2x_2 - 2x_3 = -7 \\ \\");
            sb.AppendFormat(@"&-x_1 + x_2 + 3x_3 = 3 \\ \\");
            sb.AppendFormat(@"&2x_1 - x_2 + 2x_3 = 8 \\ \\");
            RationalVector rvSolved = ACopy.CramersRule(rv);                                                                           //solve system of linear equations

            sb.AppendFormat(@"&x_1 = {0}, x_2 = {1}, x_3 = {2}", rvSolved[0].ToLatex(), rvSolved[1].ToLatex(), rvSolved[2].ToLatex()); //output values

            sb.Append(@"\end{aligned}");

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

            return(0);
        }
        public static int Test_EMatrix()
        {
            RationalFactory      rf = new RationalFactory();
            RationalSquareMatrix I  = RationalSquareMatrix.IdentityMatrix(3);


            RationalSquareMatrix ACopy = rf[3, 3,
                                            "1", "2", "-2",
                                            "-1", "1", "3",
                                            "2", "-1", "2"
                                         ];

            RationalSquareMatrix ACopy2 = rf[3, 3,
                                             "-7", "2", "-2",
                                             "-3", "1", "3",
                                             "8", "-1", "2"
                                          ];

            RationalSquareMatrix ACopy3 = rf[4, 4,

                                             "4", "7", "2", "3",
                                             "1", "3", "1", "2",
                                             "2", "5", "3", "4",
                                             "1", "4", "2", "3"
                                          ];
            string ll = RationalSquareMatrix.DetFullRep(ACopy);

            HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(ll, "Test_EMatrix.html"); //display Latex via mathjax

            return(0);
        }
        public static int Test_RationalSquareMatrix()
        {
            RationalFactory rf  = new RationalFactory();
            RealFactory     rff = new RealFactory();

            RationalSquareMatrix A = rf[3, 3,
                                        "1", "2", "-2",
                                        "-1", "1", "3",
                                        "2", "-1", "2"
                                     ];

            SquareRealMatrix SA = rff[3, 3,
                                      7, 2, -2,
                                      3, 1, 3,
                                      8, -1, 2
                                  ];
            RationalVector rv = rf["7", "3", "8"];

            StringBuilder sb = new StringBuilder();//Start building latex

            sb.Append(@"\begin{aligned}");

            sb.AppendFormat(@"&A = {0}", A.ToLatex() + @" \\ \\"); //display A matrix
            A[0] = rv;
            sb.AppendFormat(@"&Ab = {0}", A.ToLatex());            //display Vec A
            sb.AppendFormat(@"&Det = {0}", SA.Determinant());      //display Vec A
            sb.Append(@"\end{aligned}");

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

            return(0);
        }
        public static int Test_Rational_Determinant()
        {
            RationalFactory rf = new RationalFactory();

            RationalSquareMatrix A = rf[3, 3,
                                        "1", "2", "-2",
                                        "-1", "1", "3",
                                        "2", "-1", "2"
                                     ];



            RationalSquareMatrix ACopy3 = rf[4, 4,
                                             "4", "7", "2", "3",
                                             "1", "3", "1", "2",
                                             "2", "5", "3", "4",
                                             "1", "4", "2", "3"
                                          ];

            RationalSquareMatrix ACopy3_2 = rf[3, 3,
                                               1, 2, 3,
                                               4, 1, 6,
                                               7, 8, 1
                                            ];
            List <RationalCoFactorInfo> cfList = RationalSquareMatrix.GetAllMatrixCoFactors(ACopy3);

            StringBuilder sb = new StringBuilder();//Start building latex

            sb.Append(@"\begin{aligned}");
            sb.AppendFormat(@"&{0} \\ \\", ACopy3.ToLatex());

            //foreach(IGrouping<string, RationalCoFactorInfo> funk in q.ToList())
            foreach (RationalCoFactorInfo ci in cfList)
            {
                sb.AppendFormat(@"&{0} \\ \\", ci.Minor.MinorName + " = " + ((ci.Sign < 0) ? "-" : "") + ci.CoFactor.ToLatex() + ci.Minor.ToLatex());

                foreach (List <RationalCoFactorInfo> lstChild in ci.ListOfLists)
                {
                    foreach (RationalCoFactorInfo ci2 in lstChild)
                    {
                        //if (ci2.Minor.Rows == 4)
                        {
                            sb.AppendFormat(@"&{0} \\ \\", ci.Minor.MinorName + " = " + ((ci.Sign < 0) ? "-" : "") + ci.CoFactor.ToLatex() + ci2.CoFactor.ToLatex() + ci2.Minor.ToLatex());
                        }
                    }
                }
            }
            sb.Append(@"&Det = " + RationalSquareMatrix.Det(ACopy3_2));
            sb.Append(@"\end{aligned}");

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


            return(0);
        }
        public static int Test_FaddevasMethod()
        {
            RationalFactory rf = new RationalFactory();

            RationalSquareMatrix A = rf[3, 3,
                                        "1", "0", "-2",
                                        "4", "1", "0",
                                        "0", "2", "1"
                                     ];


            RationalVector       rv   = new RationalVector();
            RationalSquareMatrix AInv = RationalSquareMatrix.FaddevasMethod(A, out rv);
            StringBuilder        sb   = new StringBuilder();//Start building latex

            sb.Append(@"A^{-1} = " + AInv.ToLatex());

            HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(AInv.ToString("F"), "Test_FaddevasMethod_Determinant.html"); //display Latex via mathjax


            /*
             * RationalSquareMatrix A1 = A.Clone();
             * StringBuilder sb = new StringBuilder();//Start building latex
             * sb.Append(@"\begin{aligned}");
             * sb.AppendFormat(@"&A1 = {0} \\ \\", A1.ToLatex());
             *
             * Rational b1 = -A1.Trace();
             * sb.AppendFormat(@"&b1 = {0} \\ \\", b1.ToLatex());
             * RationalSquareMatrix I = RationalSquareMatrix.IdentityMatrix(A.Rows);
             *
             * RationalSquareMatrix B1 = A1 + (b1 * I);
             * sb.AppendFormat(@"&B1 = {0} \\ \\", B1.ToLatex());
             *
             * RationalSquareMatrix A2 = A * B1;
             * sb.AppendFormat(@"&A2 = {0} \\ \\", A2.ToLatex());
             *
             * Rational b2 = A2.Trace() / -2;
             * sb.AppendFormat(@"&b2 = {0} \\ \\", b2.ToLatex());
             *
             * I = RationalSquareMatrix.IdentityMatrix(A.Rows);
             * RationalSquareMatrix B2 = A2 + b2 * I;
             * sb.AppendFormat(@"&B2 = {0} \\ \\", B2.ToLatex());
             *
             * RationalSquareMatrix A3 = A * B2;
             * sb.AppendFormat(@"&A3 = {0} \\ \\", A3.ToLatex());
             *
             * Rational b3 = A3.Trace() / -3;
             * sb.AppendFormat(@"&b3 = {0} \\ \\", b3.ToLatex());
             *
             * RationalSquareMatrix AInv = 1/b3 * B2;
             * sb.Append(@"&A^{-1} = " + AInv.ToLatex() + @" \\ \\");
             *
             *
             * RationalSquareMatrix A_n = A;
             * Rational b_n = 1;
             * RationalSquareMatrix B_n = null;
             * int i = 0;
             * for(i = 0; i < A.Rows - 1; i++)
             * {
             *  b_n = -A_n.Trace() / (i + 1);
             *  I = RationalSquareMatrix.IdentityMatrix(A.Rows);
             *
             *  B_n = A_n + b_n * I;
             *  sb.Append(@"&Bn = " + B_n.ToLatex() + @" \\ \\");
             *
             *  A_n = A * B_n;
             *  sb.Append(@"&An = " + A_n.ToLatex() + @" \\ \\");
             * }
             *
             * b_n = -A_n.Trace() / (i + 1);
             * sb.Append(@"&bn = " + b_n.ToLatex() + @" \\ \\");
             *
             * AInv = 1/b_n * B_n;
             * sb.Append(@"&A^{-1} = " + AInv.ToLatex() + @" \\ \\");
             *
             * sb.Append(@"\end{aligned}");
             * HtmlOutputMethods.WriteLatexEqToHtmlAndLaunch(sb.ToString(), "Test_FaddevasMethod_Determinant.html"); //display Latex via mathjax
             */

            return(0);
        }