func1 function

double func1(
  1. List<DataPoint> p,
  2. double f(
    1. double
    )
)

Fits y = a*f(x) to sample data.

Implementation

double func1(List<DataPoint> p, double Function(double) f) {
  var syf = 0.0, sf2 = 0.0;
  for (final pt in p) {
    final fv = f(pt.x);
    syf += pt.y * fv;
    sf2 += fv * fv;
  }
  return syf / sf2;
}