Пример #1
0
        public static Polynomial operator +(Polynomial x, Polynomial y)
        {
            int        biggerDegree = Math.Max(x.PolynomialDegree, y.PolynomialDegree);
            Polynomial result       = new Polynomial();

            double tmp = 0.0;

            for (int i = 0; i <= biggerDegree; ++i)
            {
                tmp = 0.0;
                if (i <= x.PolynomialDegree)
                {
                    tmp += x[i];
                }
                if (i <= y.PolynomialDegree)
                {
                    tmp += y[i];
                }

                result.AddCoefficient(tmp);
            }

            result.Normalize();
            return(result);
        }
Пример #2
0
        public static Polynomial operator *(Polynomial x, Polynomial y)
        {
            Polynomial result = new Polynomial();

            for (int i = 0; i <= x.PolynomialDegree; ++i)
            {
                for (int j = 0; j <= y.PolynomialDegree; ++j)
                {
                    if (result.PolynomialDegree < i + j)
                    {
                        result.AddCoefficient(0.0);
                    }
                    result[i + j] += x[i] * y[j];
                }
            }
            result.Normalize();
            return(result);
        }
Пример #3
0
        public static Polynomial operator +(Polynomial x, Polynomial y)
        {
            int biggerDegree = Math.Max(x.PolynomialDegree, y.PolynomialDegree);
            Polynomial result = new Polynomial();

            double tmp = 0.0;
            for (int i = 0; i <= biggerDegree; ++i)
            {
                tmp = 0.0;
                if (i <= x.PolynomialDegree)
                {
                    tmp += x[i];
                }
                if (i <= y.PolynomialDegree)
                {
                    tmp += y[i];
                }

                result.AddCoefficient(tmp);
            }

            result.Normalize();
            return result;
        }
Пример #4
0
 public static Polynomial operator *(Polynomial x, Polynomial y)
 {
     Polynomial result = new Polynomial();
     for (int i = 0; i <= x.PolynomialDegree; ++i)
     {
         for (int j = 0; j <= y.PolynomialDegree; ++j)
         {
             if (result.PolynomialDegree < i + j)
             {
                 result.AddCoefficient(0.0);
             }
             result[i + j] += x[i] * y[j];
         }
     }
     result.Normalize();
     return result;
 }