Ejemplo n.º 1
0
 public static void PolyTestMult3()
 {
     polyterm[] multiplepolys = new polyterm[] { new polyterm(1, "y", 2)};
     string[] variables = new string[] { "z=2", "y=1" };
     Console.WriteLine(polyterm.equatePolyXPoly(multiplepolys, variables));
 }
Ejemplo n.º 2
0
 public static void PolyTest1()
 {
     string[] variables = new string[] { "x=5", "y=4" };
     polyterm[] anArray = new polyterm[] { new polyterm(1, "x", 1), new polyterm(1, "y", 2) };
     Console.WriteLine(polyterm.equatePolyPlusPoly(anArray, variables));
 }
Ejemplo n.º 3
0
        public static void PolyTest2()
        {
            polyterm[][] equation = new polyterm[][] { new polyterm[] { new polyterm(3, "x", 1), new polyterm(1, "y", 1) }, new polyterm[] { new polyterm(1, "x", 2), new polyterm(1, "y", 2) } };
            polyterm[] multiplepolys = new polyterm[] { new polyterm(1, "x", 2), new polyterm(1, "y", 2) };
            string[] variables = new string[] { "x=2", "y=2" };

            Console.WriteLine(polyterm.TotalPoly(equation, variables));
        }
Ejemplo n.º 4
0
        public static polyterm[] StringToMultPoly(string a)
        {
            string[] split1 = a.Split(new char[] { '*' }, System.StringSplitOptions.RemoveEmptyEntries);
            List<polyterm> aList = new List<polyterm>();

            for (int i = 0; i < split1.Length; i++)
            {
                aList.Add(OneStringToMultPoly(split1[i]));
            }

            polyterm[] anArray = new polyterm[aList.Count()];
            for (int i = 0; i < aList.Count(); i++)
            {
                anArray[i] = aList[i];
            }

            return anArray;
        }
Ejemplo n.º 5
0
 public static double TotalPoly(polyterm[][] table, string[] variables)
 {
     double sum = 0.0;
     foreach (polyterm[] arow in table)
     { sum += equatePolyXPoly(arow, variables); }
     return sum;
 }
Ejemplo n.º 6
0
        public static polyterm[] StringToMultDivPoly(string a)
        {
            bool isdivpres = false;
            foreach (char achar in a)
            {
                if (achar == '/')
                { isdivpres = true; }
            }
            if (isdivpres == false)
            { return StringToMultPoly(a); }

            char[] oper = new char[] { '*', '/' };
            string operlocation = "";

            foreach (char achar in a)
            {
                foreach (char ochar in oper)
                {
                    if (achar == ochar)
                    {operlocation += achar;}
                }
            }

            //now we have a location of repective operators.

            string[] split1 = a.Split(oper, System.StringSplitOptions.RemoveEmptyEntries);
            List<polyterm> aList = new List<polyterm>();
            for (int i = 0; i < split1.Length; i++)
            {
                if (i > 0)
                {
                    if (operlocation[i-1] == '*')
                    {
                        aList.Add(OneStringToMultPoly(split1[i]));
                        if (testprint == true) { Console.WriteLine(" [*] is used on [{0}]", split1[i]); }
                    }
                    else if (operlocation[i-1] == '/')
                    {
                        aList.Add(OneStringtoDivPoly(split1[i]));
                        if (testprint == true) { Console.WriteLine(" [/] is used on [{0}]", split1[i]); }
                    }

                }
                else
                {
                    aList.Add(OneStringToMultPoly(split1[i]));
                }
            }

            if (testprint == true)
            {
                foreach (polyterm ina in aList) { Console.WriteLine("[{0}]", ina); }
            }

            polyterm[] anArray = new polyterm[aList.Count()];
            for (int i = 0; i < aList.Count(); i++)
            {
                anArray[i] = aList[i]; //Console.Write("this"); Console.WriteLine(anArray[i]);
            }

            return anArray;
        }
Ejemplo n.º 7
0
 public static polyterm[][] ListofArrayPolytoArrayArrayPoly(List<polyterm[]> table)
 {
     polyterm[][] array = new polyterm[table.Count][];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = table[i];
     }
     return array;
 }
Ejemplo n.º 8
0
        public static double equatePolyXPoly(polyterm[] anArray, string[] variables)
        {
            string[,] variables2 = new string[variables.Length, 2];
            char[] sep = new char[] { '=', ' ' };
            int i = 0;
            foreach (string avar in variables)
            {
                string[] splitavar1 = avar.Split(sep, System.StringSplitOptions.RemoveEmptyEntries);
                foreach (string term in splitavar1)
                {
                    if (IsDigit(term) == false)
                    { variables2[i, 0] = term; variables2[i, 1] = ""; }
                    if (IsDigit(term) == true)
                    { variables2[i, 1] = term; break; }

                }
                i++;

            }

            if (testprint == true)
            {
                for (i = 0; i <= variables2.GetUpperBound(0); i++)
                {
                    for (int j = 0; j <= variables2.GetUpperBound(1); j++)
                    {
                        Console.Write("i[{0}]j[{1}]str[{2}]  ", i, j, variables2[i, j]);
                    }
                    Console.WriteLine();
                }
            }

            //check if input terms are present.

            for (i = 0; i <= variables2.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= anArray.GetUpperBound(0); j++)
                {
                    if (variables2[i, 0] == anArray[j].x)
                    {

                        break;
                    }

                }
            }

            i = 0;
            double mult = 1;
            foreach (polyterm aterm in anArray)
            {
                for (int j = 0; j <= variables2.GetUpperBound(0); j++)
                {
                    if (aterm.x == variables2[j, 0] || aterm.x == " ")
                    {
                        mult *= aterm.equateterm(double.Parse(variables2[j, 1]));
                        if (testprint == true) { Console.WriteLine("mult [{0}] aterm [{1}]", mult,aterm); }
                    }
                }
            }
            return mult;
        }
Ejemplo n.º 9
0
        public static double equatePolyPlusPoly(polyterm[] anArray, string[] variables)
        {
            string[,] variables2 = new string [variables.Length, 2];
            char[] sep = new char[] { '=' , ' '};
            int i = 0;
            foreach (string avar in variables)
            {
                string[] splitavar1 = avar.Split(sep, System.StringSplitOptions.RemoveEmptyEntries);
                foreach (string term in splitavar1)
                {
                    if (IsDigit(term) == false)
                    { variables2[i, 0] = term; variables2[i, 1] = "0"; }
                    if (IsDigit(term) == true)
                    { variables2[i, 1] = term; break; }

                }
                i++;

            }

            //check if input terms are present.

            for (i = 0; i <= variables2.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= anArray.GetUpperBound(0); j++)
                {
                    if (variables2[i, 0] == anArray[i].x)
                    {
                        break;
                    }
                    if (j == anArray.GetUpperBound(0)) { Console.WriteLine("Variable isn't present in Equation"); return 0; }
                }
            }

            i = 0;
            double sum = 0.0;
            foreach (polyterm aterm in anArray)
            {
                for (int j = 0; j <= variables2.GetUpperBound(0); j++)
                {
                    if (aterm.x == variables2[j, 0])
                    {
                        sum += aterm.equateterm(double.Parse(variables2[j, 1]));
                    }
                }
            }
            return sum;
        }
Ejemplo n.º 10
0
 public static double equate1Var(polyterm[] anArray, double x)
 {
     double sum = 0.0;
     foreach (polyterm a in anArray)
     { sum += a.equateterm(x); }
     return sum;
 }