コード例 #1
0
 /// <summary>
 /// Non-linear least-squares fitting the points (x,y) to an arbitrary function y : x -> f(p0, p1, p2, x),
 /// returning its best fitting parameter p0, p1 and p2.
 /// </summary>
 public static Tuple <double, double, double> Curve(double[] x, double[] y, Func <double, double, double, double, double> f, double initialGuess0, double initialGuess1, double initialGuess2, double tolerance = 1e-8, int maxIterations = 1000)
 {
     return(FindMinimum.OfFunction((p0, p1, p2) => Distance.Euclidean(Generate.Map(x, t => f(p0, p1, p2, t)), y), initialGuess0, initialGuess1, initialGuess2, tolerance, maxIterations));
 }
コード例 #2
0
 /// <summary>
 /// Non-linear least-squares fitting the points (x,y) to an arbitrary function y : x -> f(p, x),
 /// returning its best fitting parameter p.
 /// </summary>
 public static double Curve(double[] x, double[] y, Func <double, double, double> f, double initialGuess, double tolerance = 1e-8, int maxIterations = 1000)
 {
     return(FindMinimum.OfScalarFunction(p => Distance.Euclidean(Generate.Map(x, t => f(p, t)), y), initialGuess, tolerance, maxIterations));
 }