func3 function
Fits y = af0(x) + bf1(x) + c*f2(x) to sample data.
Implementation
({double a, double b, double c}) func3(
List<DataPoint> p,
double Function(double) f0,
double Function(double) f1,
double Function(double) f2,
) {
var m = 0.0, pp = 0.0, q = 0.0, r = 0.0, s = 0.0;
var t = 0.0, u = 0.0, v = 0.0, w = 0.0;
for (final pt in p) {
final y0 = f0(pt.x);
final y1 = f1(pt.x);
final y2 = f2(pt.x);
m += y0 * y0;
pp += y0 * y1;
q += y0 * y2;
r += y1 * y1;
s += y1 * y2;
t += y2 * y2;
u += pt.y * y0;
v += pt.y * y1;
w += pt.y * y2;
}
final d = m * r * t + 2 * pp * q * s - m * s * s - r * q * q - t * pp * pp;
return (
a: (u * (r * t - s * s) + v * (q * s - pp * t) + w * (pp * s - q * r)) / d,
b: (u * (s * q - pp * t) + v * (m * t - q * q) + w * (pp * q - m * s)) / d,
c: (u * (pp * s - r * q) + v * (pp * q - m * s) + w * (m * r - pp * pp)) / d,
);
}