Example #1
0
        // Token: 0x0600049C RID: 1180 RVA: 0x000172E8 File Offset: 0x000154E8
        public static Polynomial1 operator +(Polynomial1 left, Polynomial1 right)
        {
            MathBase.Assert(left.degree >= 0 && right.degree >= 0, "Polynomial1.operator+(Polynomial1, Polynomial1): invalid degree");
            Polynomial1 polynomial = new Polynomial1(-1);

            if (left.degree > right.degree)
            {
                polynomial.Degree = left.degree;
                for (int i = 0; i <= right.degree; i++)
                {
                    polynomial.Coeff[i] = left.Coeff[i] + right.Coeff[i];
                }
                for (int i = right.degree + 1; i <= left.degree; i++)
                {
                    polynomial.Coeff[i] = left.Coeff[i];
                }
            }
            else
            {
                polynomial.Degree = right.degree;
                for (int i = 0; i <= left.degree; i++)
                {
                    polynomial.Coeff[i] = left.Coeff[i] + right.Coeff[i];
                }
                for (int i = left.degree + 1; i <= right.degree; i++)
                {
                    polynomial.Coeff[i] = right.Coeff[i];
                }
            }
            return(polynomial);
        }
Example #2
0
        // Token: 0x060004F0 RID: 1264 RVA: 0x0001A3E4 File Offset: 0x000185E4
        public bool AllRealPartsPositive(Polynomial1 poly)
        {
            int degree = poly.Degree;

            double[] array = new double[degree + 1];
            int      num   = 0;

            foreach (double num2 in poly.Coefficients)
            {
                array[num++] = num2;
            }
            int i;

            if (array[degree] != 1.0)
            {
                double num3 = 1.0 / array[degree];
                for (i = 0; i < degree; i++)
                {
                    array[i] *= num3;
                }
                array[degree] = 1.0;
            }
            int num4 = -1;

            i = degree - 1;
            while (i >= 0)
            {
                array[i] *= (double)num4;
                i--;
                num4 = -num4;
            }
            return(PolynomialRoots.AllRealPartsNegative(degree, array));
        }
Example #3
0
        // Token: 0x060004A0 RID: 1184 RVA: 0x000175AE File Offset: 0x000157AE
        public static Polynomial1 operator -(Polynomial1 poly, double scalar)
        {
            MathBase.Assert(poly.degree >= 0, "Polynomial1 operator -(Polynomial1, double): invalid degree");
            Polynomial1 polynomial = new Polynomial1(poly.Coeff);

            polynomial.Coeff[0] -= scalar;
            return(polynomial);
        }
Example #4
0
        // Token: 0x060004A7 RID: 1191 RVA: 0x0001783C File Offset: 0x00015A3C
        public Polynomial1 GetInversion()
        {
            Polynomial1 polynomial = new Polynomial1(this.degree);

            for (int i = 0; i <= this.degree; i++)
            {
                polynomial.Coeff[i] = this.Coeff[this.degree - i];
            }
            return(polynomial);
        }
Example #5
0
        // Token: 0x060004A4 RID: 1188 RVA: 0x0001771C File Offset: 0x0001591C
        public static Polynomial1 operator -(Polynomial1 poly)
        {
            MathBase.Assert(poly.degree >= 0, "Polynomial1 operator -(Polynomial1): invalid degree");
            Polynomial1 polynomial = new Polynomial1(poly.degree);

            for (int i = 0; i <= poly.degree; i++)
            {
                polynomial.Coeff[i] = -poly.Coeff[i];
            }
            return(polynomial);
        }
Example #6
0
        // Token: 0x060004A1 RID: 1185 RVA: 0x000175E4 File Offset: 0x000157E4
        public static Polynomial1 operator *(Polynomial1 poly, double scalar)
        {
            MathBase.Assert(poly.degree >= 0, "Polynomial1 operator *(Polynomial1, double): invalid degree");
            Polynomial1 polynomial = new Polynomial1(poly.degree);

            for (int i = 0; i <= poly.degree; i++)
            {
                polynomial.Coeff[i] = scalar * poly.Coeff[i];
            }
            return(polynomial);
        }
Example #7
0
        // Token: 0x0600049E RID: 1182 RVA: 0x000174F0 File Offset: 0x000156F0
        public static Polynomial1 operator *(Polynomial1 left, Polynomial1 right)
        {
            MathBase.Assert(left.degree >= 0 && right.degree >= 0, "Polynomial1.operator*(Polynomial1, Polynomial1): invalid degree");
            Polynomial1 polynomial = new Polynomial1(left.degree + right.degree);

            for (int i = 0; i <= left.degree; i++)
            {
                for (int j = 0; j <= right.degree; j++)
                {
                    int num = i + j;
                    polynomial.Coeff[num] += left.Coeff[i] * right.Coeff[j];
                }
            }
            return(polynomial);
        }
Example #8
0
        // Token: 0x060004F2 RID: 1266 RVA: 0x0001A594 File Offset: 0x00018794
        private bool Bisection(Polynomial1 poly, double minX, double maxX, int digits, out double root)
        {
            double num = poly.Evaluate(minX);

            if (Math.Abs(num) <= this.epsilon)
            {
                root = minX;
                return(true);
            }
            double num2 = poly.Evaluate(maxX);

            if (Math.Abs(num2) <= this.epsilon)
            {
                root = maxX;
                return(true);
            }
            root = 0.0;
            if (num * num2 > 0.0)
            {
                return(false);
            }
            double num3 = Math.Log(maxX - minX);
            double num4 = (double)digits * Math.Log(10.0);
            int    num5 = (int)((num3 + num4) / Math.Log(2.0) + 0.5);

            for (int i = 0; i < num5; i++)
            {
                root = 0.5 * (minX + maxX);
                double num6 = poly.Evaluate(root);
                double num7 = num6 * num;
                if (num7 < 0.0)
                {
                    maxX = root;
                }
                else
                {
                    if (num7 <= 0.0)
                    {
                        break;
                    }
                    minX = root;
                    num  = num6;
                }
            }
            return(true);
        }
Example #9
0
        // Token: 0x060004A9 RID: 1193 RVA: 0x00017918 File Offset: 0x00015B18
        public void Divide(Polynomial1 div, out Polynomial1 quot, out Polynomial1 rem, double epsilon)
        {
            quot = new Polynomial1(-1);
            int num = this.degree - div.degree;

            if (num >= 0)
            {
                quot.Degree = num;
                Polynomial1 polynomial = new Polynomial1(this.Coeff);
                double      num2       = 1.0 / div[div.degree];
                for (int i = num; i >= 0; i--)
                {
                    int j = div.degree + i;
                    quot[i] = num2 * polynomial[j];
                    for (j--; j >= i; j--)
                    {
                        Polynomial1 polynomial2 = polynomial;
                        int         i2          = j;
                        polynomial2[i2] -= quot[i] * div[j - i];
                    }
                }
                int num3 = div.degree - 1;
                while (num3 > 0 && Math.Abs(polynomial[num3]) < epsilon)
                {
                    num3--;
                }
                if (num3 == 0 && Math.Abs(polynomial[0]) < epsilon)
                {
                    polynomial[0] = 0.0;
                }
                rem = new Polynomial1(num3);
                for (int k = 0; k <= num3; k++)
                {
                    rem[k] = polynomial[k];
                }
                return;
            }
            quot.Degree = 0;
            quot[0]     = 0.0;
            rem         = new Polynomial1(this.Coeff);
        }
Example #10
0
        // Token: 0x060004A3 RID: 1187 RVA: 0x0001768C File Offset: 0x0001588C
        public static Polynomial1 operator /(Polynomial1 poly, double scalar)
        {
            MathBase.Assert(poly.degree >= 0, "Polynomial1 operator /(Polynomial1, double): invalid degree");
            Polynomial1 polynomial = new Polynomial1(poly.degree);

            if (scalar != 0.0)
            {
                double num = 1.0 / scalar;
                for (int i = 0; i <= poly.degree; i++)
                {
                    polynomial.Coeff[i] = num * poly.Coeff[i];
                }
            }
            else
            {
                for (int i = 0; i <= poly.degree; i++)
                {
                    polynomial.Coeff[i] = double.MaxValue;
                }
            }
            return(polynomial);
        }
Example #11
0
 // Token: 0x060004A6 RID: 1190 RVA: 0x000177C4 File Offset: 0x000159C4
 public Polynomial1 GetDerivative()
 {
     if (this.degree > 0)
     {
         Polynomial1 polynomial = new Polynomial1(this.degree - 1);
         int         i          = 0;
         int         num        = 1;
         while (i < this.degree)
         {
             polynomial.Coeff[i] = (double)num * this.Coeff[num];
             i++;
             num++;
         }
         return(polynomial);
     }
     if (this.degree == 0)
     {
         Polynomial1 polynomial2 = new Polynomial1(0);
         polynomial2.Coeff[0] = 0.0;
         return(polynomial2);
     }
     return(new Polynomial1(-1));
 }
Example #12
0
        // Token: 0x060004ED RID: 1261 RVA: 0x0001A104 File Offset: 0x00018304
        public double GetBound(Polynomial1 poly)
        {
            Polynomial1 polynomial = new Polynomial1(poly.Coefficients);

            polynomial.Compress(this.epsilon);
            int degree = polynomial.Degree;

            if (degree < 1)
            {
                return(-1.0);
            }
            double num  = 1.0 / polynomial[degree];
            double num2 = 0.0;

            for (int i = 0; i < degree; i++)
            {
                double num3 = Math.Abs(polynomial[i]) * num;
                if (num3 > num2)
                {
                    num2 = num3;
                }
            }
            return(1.0 + num2);
        }
Example #13
0
        // Token: 0x060004EE RID: 1262 RVA: 0x0001A190 File Offset: 0x00018390
        public bool FindB(Polynomial1 poly, double minX, double maxX, int digits)
        {
            if (poly.Degree > this.maxRoot)
            {
                this.maxRoot = poly.Degree;
                this.Roots   = new double[this.maxRoot];
            }
            double num2;

            if (poly.Degree != 1)
            {
                Polynomial1 derivative = poly.GetDerivative();
                this.FindB(derivative, minX, maxX, digits);
                int      num   = 0;
                double[] array = new double[this.Count + 1];
                if (this.Count > 0)
                {
                    if (this.Bisection(poly, minX, this.Roots[0], digits, out num2))
                    {
                        array[num++] = num2;
                    }
                    for (int i = 0; i <= this.Count - 2; i++)
                    {
                        if (this.Bisection(poly, this.Roots[i], this.Roots[i + 1], digits, out num2))
                        {
                            array[num++] = num2;
                        }
                    }
                    if (this.Bisection(poly, this.Roots[this.Count - 1], maxX, digits, out num2))
                    {
                        array[num++] = num2;
                    }
                }
                else if (this.Bisection(poly, minX, maxX, digits, out num2))
                {
                    array[num++] = num2;
                }
                if (num > 0)
                {
                    this.Count    = 1;
                    this.Roots[0] = array[0];
                    for (int i = 1; i < num; i++)
                    {
                        if (Math.Abs(array[i] - array[i - 1]) > this.epsilon)
                        {
                            double[] roots = this.Roots;
                            int      count = this.Count;
                            this.Count   = count + 1;
                            roots[count] = array[i];
                        }
                    }
                }
                else
                {
                    this.Count = 0;
                }
                return(this.Count > 0);
            }
            if (this.Bisection(poly, minX, maxX, digits, out num2))
            {
                this.Count    = 1;
                this.Roots[0] = num2;
                return(true);
            }
            this.Count = 0;
            return(false);
        }
Example #14
0
        // Token: 0x060004EC RID: 1260 RVA: 0x0001A0E4 File Offset: 0x000182E4
        public bool FindB(Polynomial1 poly, int digits)
        {
            double bound = this.GetBound(poly);

            return(this.FindB(poly, -bound, bound, digits));
        }