Curve fit with "polynom" y = a + b.x + c.x^-2 + d.x^2


#1

Hi,

is there a possiblity to do a curve fit with a “polynomial” containing negative exponents (so it is not really a polynomial)? I should get the coefficients base on on a curve with several thousands of value pairs providing the grade of the polynomial and the exponents.

Thank you for your Support,

Klaus


(Christoph Rüegg) #2

Certainly - such a function is still a linear combination. For example:

var x = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0 };
var y = new double[] { 2.0, 6.0, -4.5, 1.5, 2.0 };

Fit.LinearCombination(x, y,
     t => 1.0, t => t, t => Math.Pow(t,-2.0), t => Math.Pow(t,2.0));

Returns:

// 47.3035909273377  (a)
// -24.9907860729208 (b)
// -23.4468251690964 (c)
// 3.26656127808895  (d)

#3

Hi cdrnet,

great - it works!

Thank you for your support!

Best regards,

Klaus