From 4bd78fa017c085f411ac9e35d3813e2929e5c6e7 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Wed, 22 May 2013 22:55:14 +0200 Subject: [PATCH] New Evaluate.Polynomial overload that is easier to use --- src/Numerics/SpecialFunctions/Evaluate.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Numerics/SpecialFunctions/Evaluate.cs b/src/Numerics/SpecialFunctions/Evaluate.cs index b170082a..22e06419 100644 --- a/src/Numerics/SpecialFunctions/Evaluate.cs +++ b/src/Numerics/SpecialFunctions/Evaluate.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2012 Math.NET +// Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -61,6 +61,7 @@ namespace MathNet.Numerics /// The coefficients of the polynomial. /// The location where to evaluate the polynomial at. /// the evaluation of the polynomial. + [Obsolete("Use Polynomial(z, params coefficients) instead.")] public static double Polynomial(double[] coefficients, double z) { int count = coefficients.Length; @@ -74,6 +75,25 @@ 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 double Polynomial(double z, params double[] coefficients) + { + double 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 ///