Exemple #1
0
        /// <summary>
        /// Returns the string which represents this polynomial.
        /// </summary>
        /// <returns>The string which represents this polynomial.</returns>
        public override string ToString()
        {
            if (CoefficientsOrg.Count == 0)
            {
                return("0");
            }

            var monomialsQuery = CoefficientsOrg
                                 .OrderByDescending(c => c.Key)
                                 .Select((c, i) => ToMonomialString(c.Key, c.Value, i == 0));

            return(string.Join("", monomialsQuery));
        }
Exemple #2
0
 /// <summary>
 /// Gets the coefficient for the specified index.
 /// </summary>
 /// <param name="index">The index of the variable.</param>
 /// <returns>The coefficient for the specified index.</returns>
 public double this[int index]
 {
     get { return(CoefficientsOrg.ContainsKey(index) ? CoefficientsOrg[index] : 0); }
 }
Exemple #3
0
 /// <summary>
 /// Substitutes the specified value into this polynomial.
 /// </summary>
 /// <param name="value">The value to substitute.</param>
 /// <returns>The calculated value.</returns>
 public double Substitute(double value)
 {
     return(CoefficientsOrg.Sum(c => c.Value * Math.Pow(value, c.Key)));
 }