Exemple #1
0
        public static SymbolMatrix operator /(SymbolMatrix a, SymbolMatrix b)
        {
            SymbolMatrix retVal = new SymbolMatrix(a.Rows, a.Columns);

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

            StringBuilder sb = new StringBuilder();

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

            retVal.FullRep = sb.ToString();
            return(retVal);
        }
Exemple #2
0
        /***************************Operators**********************************/

        private static SymbolMatrix MultiplyRational(SymbolMatrix a, SymbolMatrix b)
        {
            SymbolMatrix retVal = new SymbolMatrix(a.Rows, a.Columns);

            retVal.SymbolMatrixSymbolType = SymbolType.Rational;

            for (int rowCount = 0; rowCount < retVal.Rows; rowCount++)
            {
                for (int colCount = 0; colCount < retVal.Columns; colCount++)
                {
                    for (int retColCount = 0; retColCount < retVal.Columns; retColCount++)
                    {
                        Rational inter = Rational.Parse(retVal.InternalRep[rowCount, colCount].Expression);
                        inter += Rational.Parse(a.InternalRep[rowCount, retColCount].Expression) * Rational.Parse(b.InternalRep[retColCount, colCount].Expression);
                        Symbol sym = new Symbol(inter.ToString());
                        sym.LatexString = inter.ToLatex();
                        retVal.InternalRep[rowCount, colCount] = sym;
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

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

            retVal.FullRep = sb.ToString();

            return(retVal);
        }
Exemple #3
0
        public static List <CoFactorInfo> GetCoFactors(SymbolMatrix ParentMatrix)
        {
            List <CoFactorInfo> cfiL = new List <CoFactorInfo>();
            int Order = ParentMatrix.Rows;

            for (int colCount = 0; colCount < ParentMatrix.Columns; colCount++)
            {
                cfiL.Add(GetCoFactor(ParentMatrix, colCount + 1));
            }
            return(cfiL);
        }
Exemple #4
0
        /***************************End of Operators**********************************/

        public SymbolMatrix Flip()
        {
            SymbolMatrix flipper = new SymbolMatrix(this.Rows, this.Columns);

            for (int rowCount = 0; rowCount < Rows; rowCount++)
            {
                int MaxColumn = this.Columns - 1;
                for (int colCount = 0; colCount < Columns; colCount++)
                {
                    flipper[rowCount, MaxColumn] = this[rowCount, colCount];
                    --MaxColumn;
                }
            }
            return(flipper);
        }
Exemple #5
0
        public SymbolMatrix ReName(List <string> newSymbols)
        {
            SymbolMatrix flipper = new SymbolMatrix(this.Rows, this.Columns);
            RowOrColumn  rc      = new RowOrColumn();

            rc.rowColumn = RowColumn.Row;
            rc.Val       = 0;

            SymbolVector oldSymbols = this[rc];

            for (int rowCount = 0; rowCount < Rows; rowCount++)
            {
                for (int colCount = 0; colCount < Columns; colCount++)
                {
                    int    ind = oldSymbols.FindIndex(f => f.Expression == this[rowCount, colCount].Expression);
                    Symbol sym = new Symbol(newSymbols[ind]);
                    sym.IsExpression            = true;
                    flipper[rowCount, colCount] = sym;
                }
            }
            return(flipper);
        }
Exemple #6
0
        public static CoFactorInfo GetCoFactor(SymbolMatrix symIn, int Column)
        {
            CoFactorInfo cfi = new CoFactorInfo();

            cfi.Sign = (int)Math.Pow(-1, Column + 1);
            SymbolVector col = symIn[Column - 1];

            cfi.CoFactor = col[0];
            List <Symbol> symList = new List <Symbol>();

            for (int rowCount = 1; rowCount < symIn.Rows; rowCount++)
            {
                for (int colCount = 0; colCount < symIn.Columns; colCount++)
                {
                    if (colCount + 1 != Column)
                    {
                        symList.Add(symIn[rowCount, colCount]);
                    }
                }
            }

            cfi.Minor = new SymbolMatrix(symIn.Rows - 1, symIn.Columns - 1, symList);
            return(cfi);
        }
Exemple #7
0
        public static List <CoFactorInfo> GetAllMatrixCoFactors(SymbolMatrix ParentMatrix)
        {
            List <CoFactorInfo> cfList = SymbolMatrix.GetCoFactors(ParentMatrix);

            if (cfList[0].Minor.Rows == 2) //At two go back
            {
                return(cfList);
            }
            int                 inc         = 0;
            CoFactorInfo        cfi         = null;
            CoFactorInfo        cfiChild    = null;
            List <CoFactorInfo> cfListChild = null;

            while (inc < cfList.Count)
            {
                if (cfi == null)
                {
                    cfi = cfList[inc];
                }
                else if (cfi != null && cfi.ListOfLists.Count == 0) //init value
                {
                    List <CoFactorInfo> cfListTmp = SymbolMatrix.GetCoFactors(cfi.Minor);
                    cfi.ListOfLists.Add(cfListTmp);
                    cfListChild = new List <CoFactorInfo>(cfListTmp);
                    if (cfListChild[0].Minor.Rows == 2) //end of line
                    {
                        cfList[inc] = cfi;
                        cfi         = null;
                        inc++;
                    }
                }
                else if (cfi != null && cfi.ListOfLists.Count > 0) //have value
                {
                    List <CoFactorInfo> cfListTmp = null;
                    cfiChild = new CoFactorInfo();
                    foreach (CoFactorInfo cfiC in cfListChild)
                    {
                        cfListTmp = SymbolMatrix.GetCoFactors(cfiC.Minor);
                        cfi.ListOfLists.Add(cfListTmp);
                        cfiChild.ListOfLists.Add(cfListTmp);
                    }

                    cfListChild = new List <CoFactorInfo>();
                    foreach (List <CoFactorInfo> cfl in cfiChild.ListOfLists)
                    {
                        foreach (CoFactorInfo cfiC in cfl)
                        {
                            cfListChild.Add(cfiC);
                        }
                    }

                    cfiChild = null;

                    if (cfListChild[0].Minor.Rows == 2) //end of line
                    {
                        cfList[inc] = cfi;
                        cfi         = null;
                        inc++;
                    }
                }
            }

            return(cfList);
        }