Search code examples
c#mathcurve-fittingpow

Using Math.Net Numerics, how to find a curve fitting for "Power"


I'm trying to reproduce same curve fitting (called "trending") in Excel but in C#: Exponential, Linear, Logarithmic, Polynomial and Power.

I found linear and polynomial as :

Tuple<double, double> line = Fit.Line(xdata, ydata); 
double[] poly2 = Fit.Polynomial(xdata, ydata, 2);

I also found Exponential fit.

But I wonder how to do curve fitting for Power. Anybody has an idea?

I should be able to get both constants like shown into the Excel screen shot formula:

  • power
  • multiplier (before x)

enter image description here


Solution

  • I asked the question directly to the forum of mathdotnet (that I recently discovered). Christoph Ruegg, the main developper of the lib, answered me something excellent that I want to share in order to help other with the same problem:

    Assuming with power you’re referring to a target function along the lines of y : x -> a*x^b, then this is a simpler version of what I’ve described in Linearizing non-linear models by transformation.

    This seems to be used often enough so I’ve started to add a new Fit.Power and Fit.Exponential locally for this case - not pushed yet since it first needs more testing, but I expect it to be part of v4.1.

    Alternatively, by now we also support non-linear optimization which could also be used for use cases like this (FindMinimum module).

    Link to my question: mathdonet - Curve fitting: Power