 # I need help with the Function Parameter for Fit.Curve

Hi Everyone!

I’m working with the Math.NET Numerics library v7.0 for C#, I’m using the Fit.Curve method in two different ways depending on the scenario

Scenario 1) Tuple<double, double> Curve(double[] x, double[] y, Func<double, double, double, double> f , double initialGuess0, double initialGuess1);

Scenario 2) Tuple<double, double, double> Curve(double[] x, double[] y, Func<double, double, double, double, double> f , double initialGuess0, double initialGuess1, double initialGuess2);

But I have a problem, I don’t know exactly what I need to use for the function required in the f parameter Do you have an example for this?

Another question that I have is: Can I use the same function in both scenarios?

This is what I’m trying to do:

var x = new double[] { 0, 3, 6, 9, 12, 15 };
var y = new double[] {0.00, 0.16, 0.32, 0.48, 0.64, 0.80};

var result = Fit.Curve(
x,
y,
null,//What do I need for this?
initialGuess0: 2.5,
initialGuess1: 4.53
);

Greetings

You may be going about this wrong. The most common way to fit a curve to data is to use a polynomial. For example, find values for A, B, and C that give the best fit for the function like this:

y = A + Bx + Cx^2

The Fit.Curve function is designed for situations where the fitted function is not a polynomial, and you know that that form is, for example

y = Ax + Bx + ABx^2

In this case, you would create the function f something like this:

var f = new Func<double, double, double, double>((x, A, B) => A * x + B * x + A * B * x * x);

It would be easier to help if we had a more complete explanation.

1 Like

This is exactly what I needed, I just wanted to know how I can define the formula. Thank you very much.