std::vector<std::function<double(double)>> fitfunctions =
{f1,...,fm};
double fitfunctions(int i, double x){return fi(x);}
#include<math.h> // NAN is there
double funs(int i, double x){
switch(i){
case 0: return 1.0; break;
case 1: return x; break;
case 2: return x*x; break;
default: {fprintf(stderr,"funs: wrong i:%d",i); return NAN;}
}
}
Hint: the variation of y with respect to variations of
a and b
as function of x is given as
δy = δa + δb x.
Therefore
δy2 = δa2 + δb2
x2 +2δa δb x.
For normally distributed a and b this translates into
Δy2(x) =
Δa2 +
Δb2x2 + 2<δa δb>x
where <δa δb> is the covariance.
I ran out of ideas. Make up an interesting exercise here, so we can use it next year.