Ejemplo n.º 1
0
        public Polynomial2D Evaluate(double Val, int Dim) // turn a 2d polynomial into a regular one
        {
            Polynomial2D pAns;

            if (Dim == 0)
            {
                pAns = new Polynomial2D(0, yOrder);
            }
            else if (Dim == 1)
            {
                pAns = new Polynomial2D(xOrder, 0);
            }
            else
            {
                throw new Exception("Dimension must be 0 or 1");
            }

            for (int i = 0; i <= xOrder; i++)
            {
                for (int j = 0; j <= yOrder; j++)
                {
                    if (Dim == 0)
                    {
                        pAns.coefficients[0, j] += pAns.coefficients[i, j] * Math.Pow(Val, i);
                    }
                    else
                    {
                        pAns.coefficients[i, 0] += pAns.coefficients[i, j] * Math.Pow(Val, j);
                    }
                }
            }
            return(pAns);
        }
Ejemplo n.º 2
0
        public Polynomial2D Convert_2D(int Dim)
        {
            Polynomial2D p2d;

            if (Dim == 0)
            {
                p2d = new Polynomial2D(order, 0);
            }
            else if (Dim == 1)
            {
                p2d = new Polynomial2D(0, order);
            }
            else
            {
                throw new Exception("Dim must be 0, 1, or 2");
            }
            int idx = 0;

            for (int i = 0; i <= p2d.xOrder; i++)
            {
                for (int j = 0; j <= p2d.yOrder; j++)
                {
                    p2d.coefficients[i, j] = coefficients[idx];
                    idx++;
                }
            }
            return(p2d);
        }
Ejemplo n.º 3
0
        public static Polynomial2D operator +(Polynomial2D p2, Polynomial2D p1)
        {
            var coefficients = addArrays(p2.coefficients, p1.coefficients);
            var p3           = new Polynomial2D(coefficients);

            return(p3);
        }
Ejemplo n.º 4
0
        public static Polynomial2D operator *(Polynomial2D p1, double Scalar)
        {
            var p2 = new Polynomial2D(p1.xOrder, p1.yOrder);

            for (int i = 0; i <= p2.xOrder; i++)
            {
                for (int j = 0; j <= p2.yOrder; j++)
                {
                    p2.coefficients[i, j] = Scalar * p1.coefficients[i, j];
                }
            }
            return(p2);
        }
Ejemplo n.º 5
0
        public static Polynomial2D operator *(Polynomial2D p2, Polynomial2D p1)
        {
            var p3 = new Polynomial2D(p2.xOrder + p1.xOrder, p2.yOrder + p1.yOrder);

            for (int i1 = 0; i1 <= p1.xOrder; i1++)
            {
                for (int i2 = 0; i2 <= p2.xOrder; i2++)
                {
                    for (int j1 = 0; j1 <= p1.yOrder; j1++)
                    {
                        for (int j2 = 0; j2 <= p2.yOrder; j2++)
                        {
                            p3.coefficients[i1 + i2, j1 + j2] += p2.coefficients[i2, j2] * p1.coefficients[i1, j1];
                        }
                    }
                }
            }
            return(p3);
        }
Ejemplo n.º 6
0
        public Polynomial2D Differentiate(int Dim)
        {
            int xOrderNew;
            int yOrderNew;

            if (Dim == 0)
            {
                xOrderNew = Math.Max(xOrder - 1, 0);
                yOrderNew = yOrder;
            }
            else if (Dim == 1)
            {
                yOrderNew = Math.Max(yOrder - 1, 0);
                xOrderNew = xOrder;
            }
            else
            {
                throw new Exception("Dimension must be 0 or 1");
            }
            var pDiff = new Polynomial2D(xOrderNew, yOrderNew);

            for (int i = 0; i <= xOrderNew; i++)
            {
                for (int j = 0; j <= yOrderNew; j++)
                {
                    if (Dim == 0)
                    {
                        pDiff.coefficients[i, j] = coefficients[i + 1, j] * (i + 1);
                    }
                    else
                    {
                        pDiff.coefficients[i, j] = coefficients[i, j + 1] * (j + 1);
                    }
                }
            }
            return(pDiff);
        }
Ejemplo n.º 7
0
        public Polynomial2D Integrate(int Dim)
        {
            int xOrderNew;
            int yOrderNew;

            if (Dim == 0)
            {
                xOrderNew = Math.Max(xOrder + 1, 1);
                yOrderNew = yOrder;
            }
            else if (Dim == 1)
            {
                yOrderNew = Math.Max(yOrder + 1, 1);
                xOrderNew = xOrder;
            }
            else
            {
                throw new Exception("Dimension must be 0 or 1");
            }
            var pInt = new Polynomial2D(xOrderNew, yOrderNew);

            for (int i = 0; i <= xOrderNew; i++)
            {
                for (int j = 0; j <= yOrderNew; j++)
                {
                    if (Dim == 0 && i > 0)
                    {
                        pInt.coefficients[i, j] = coefficients[i - 1, j] / ((double)i);
                    }
                    else if (Dim == 1 && j > 0)
                    {
                        pInt.coefficients[i, j] = coefficients[i, j - 1] / ((double)j);
                    }
                }
            }
            return(pInt);
        }