コード例 #1
0
ファイル: Polynomial.cs プロジェクト: xiaodelea/dodoni.net
 /// <summary>Gets the (complex) roots of a specified polynomial of degree up to 2.
 /// </summary>
 /// <param name="absoluteCoefficient">The absolute coefficient.</param>
 /// <param name="firstOrderCoefficient">The first order coefficient.</param>
 /// <param name="secondOrderCoefficient">The second order coefficient.</param>
 /// <param name="thirdOrderCoefficient">The third order coefficient.</param>
 /// <param name="firstRoot">The first root (output).</param>
 /// <param name="secondRoot">The second root (output).</param>
 /// <param name="thirdRoot">The third root (output).</param>
 /// <returns>The order of the polynomial represented by the coefficients, i.e. the number of roots.</returns>
 public static int GetRoots(System.Numerics.Complex absoluteCoefficient, System.Numerics.Complex firstOrderCoefficient, System.Numerics.Complex secondOrderCoefficient, System.Numerics.Complex thirdOrderCoefficient, out System.Numerics.Complex firstRoot, out System.Numerics.Complex secondRoot, out System.Numerics.Complex thirdRoot)
 {
     if (thirdOrderCoefficient.Equals(System.Numerics.Complex.Zero) == false)  // degree 3
     {
         ComplexDegreeThreePolynomial.GetRoots(absoluteCoefficient, firstOrderCoefficient, secondOrderCoefficient, thirdOrderCoefficient, out firstRoot, out secondRoot, out thirdRoot);
         return(3);
     }
     if (secondOrderCoefficient.Equals(System.Numerics.Complex.Zero) == false)   // degree 2
     {
         ComplexDegreeTwoPolynomial.GetRoots(absoluteCoefficient, firstOrderCoefficient, secondOrderCoefficient, out firstRoot, out secondRoot);
         thirdRoot = new System.Numerics.Complex(Double.NaN, Double.NaN);
         return(2);
     }
     else if (firstOrderCoefficient.Equals(System.Numerics.Complex.Zero) == false) // degree 1
     {
         firstRoot  = unchecked (-absoluteCoefficient / firstOrderCoefficient);    // the highest coefficient is always != 0.0, but maybe near 0.0
         secondRoot = thirdRoot = new System.Numerics.Complex(Double.NaN, Double.NaN);
         return(1);
     }
     else  // degree 0
     {
         firstRoot = secondRoot = thirdRoot = new System.Numerics.Complex(Double.NaN, Double.NaN);
         return(0);
     }
 }
コード例 #2
0
 public static bool IsZero(this Complex self)
 {
     return(self.Equals(Complex.Zero));
 }