|
|
|
@ -50,6 +50,10 @@ namespace MathNet.Numerics |
|
|
|
{ |
|
|
|
using System; |
|
|
|
|
|
|
|
#if !NOSYSNUMERICS
|
|
|
|
using Complex = System.Numerics.Complex; |
|
|
|
#endif
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Evaluation functions, useful for function approximation.
|
|
|
|
/// </summary>
|
|
|
|
@ -74,6 +78,44 @@ namespace MathNet.Numerics |
|
|
|
return sum; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="z">The location where to evaluate the polynomial at.</param>
|
|
|
|
/// <param name="coefficients">The coefficients of the polynomial, coefficient for power k at index k.</param>
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="z">The location where to evaluate the polynomial at.</param>
|
|
|
|
/// <param name="coefficients">The coefficients of the polynomial, coefficient for power k at index k.</param>
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Numerically stable series summation
|
|
|
|
/// </summary>
|
|
|
|
|