diff --git a/src/Numerics/SpecialFunctions/Evaluate.cs b/src/Numerics/SpecialFunctions/Evaluate.cs index 366b0d9c..73fc6ed2 100644 --- a/src/Numerics/SpecialFunctions/Evaluate.cs +++ b/src/Numerics/SpecialFunctions/Evaluate.cs @@ -50,6 +50,10 @@ namespace MathNet.Numerics { using System; +#if !NOSYSNUMERICS + using Complex = System.Numerics.Complex; +#endif + /// /// Evaluation functions, useful for function approximation. /// @@ -74,6 +78,44 @@ namespace MathNet.Numerics return sum; } + /// + /// Evaluate a polynomial at point x. + /// Coefficients are ordered by power with power k at index k. + /// Example: coefficients [3,-1,2] represent y=2x^2-x+3. + /// + /// The location where to evaluate the polynomial at. + /// The coefficients of the polynomial, coefficient for power k at index k. + public static Complex Polynomial(Complex z, params double[] coefficients) + { + Complex sum = coefficients[coefficients.Length - 1]; + for (int i = coefficients.Length - 2; i >= 0; --i) + { + sum *= z; + sum += coefficients[i]; + } + + return sum; + } + + /// + /// Evaluate a polynomial at point x. + /// Coefficients are ordered by power with power k at index k. + /// Example: coefficients [3,-1,2] represent y=2x^2-x+3. + /// + /// The location where to evaluate the polynomial at. + /// The coefficients of the polynomial, coefficient for power k at index k. + public static Complex Polynomial(Complex z, params Complex[] coefficients) + { + Complex sum = coefficients[coefficients.Length - 1]; + for (int i = coefficients.Length - 2; i >= 0; --i) + { + sum *= z; + sum += coefficients[i]; + } + + return sum; + } + /// /// Numerically stable series summation ///