Exemple #1
0
        /// <summary>
        /// overloading operator - for normal subtraction of 2 polinomial
        /// </summary>
        /// <param name="p1">first polinomial in subtraction</param>
        /// <param name="p2">second polinomial in subtraction</param>
        /// <returns>Subtraction Polinomial</returns>
        public static Polinomial operator -(Polinomial p1, Polinomial p2)
        {
            List <double> newCoef   = new List <double>();
            int           maxDegree = (p1.degree > p2.degree) ? p1.degree : p2.degree;


            int lenP1 = p1.coefs.Length;
            int lenP2 = p2.coefs.Length;

            for (int i = 0; i < maxDegree; i++)
            {
                if (i < lenP1 && i < lenP2)
                {
                    newCoef.Add(p1.coefs[i] - p2.coefs[i]);
                }

                if (i >= lenP1)
                {
                    newCoef.Add(0 - p2.coefs[i]);
                }

                if (i >= lenP2)
                {
                    newCoef.Add(p1.coefs[i] - 0);
                }
            }

            Polinomial newPol = new Polinomial(newCoef.ToArray(), maxDegree);

            return(newPol);
        }
Exemple #2
0
        /// <summary>
        /// Overriding method Equals of 2 object
        /// </summary>
        /// <param name="obj">object whith which compare</param>
        /// <returns>bool value of equity of polinomials</returns>
        /// <exception cref="ArgumentNullException">if the object null</exception>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            Polinomial polin = obj as Polinomial;

            return(this == polin);
        }
Exemple #3
0
        /// <summary>
        /// overloading operator * for normal multiplying of 2 polinomial
        /// </summary>
        /// <param name="p1">first polinomial in multiplying</param>
        /// <param name="p2">second polinomial in multiplying</param>
        /// <returns>multiplying Polinomial</returns>
        public static Polinomial operator *(Polinomial p1, Polinomial p2)
        {
            int maxDegree = p1.getDegree() + p2.getDegree();

            double[] coefP3 = new double[maxDegree + 1];

            for (int i = p1.getDegree(); i >= 0; i--)
            {
                for (int j = p2.getDegree(); j >= 0; j--)
                {
                    coefP3[i + j] += p1.getCoef()[i] * p2.getCoef()[j];
                }
            }

            Polinomial p3 = new Polinomial(coefP3, maxDegree);

            return(p3);
        }