I'm trying to fit a number of data sets. Each of the sets should evaluate to a simple linear solution.ax+b
.
The problem is, all data sets have interference from a function of the form cx^2+dx
.
So, what I'm trying to do is evaluate the sets together such that each set gets a resulting fit of the form ax+b+e(cx^2+dx)
, where e
varies per data set, where c
and d
are the same across all data sets, with a
and b
either seperate or together.
For instance three small sets:
data1={{11/1250, 1.96334}, {19/1250, 9.32588}, {3/125, 19.1426}, {17/500,28.4685},
{1/20, 40.2486}, {9/125, 54.9736}, {9/100, 65.772}, {11/100, 82.4604},
{33/250,93.2588},{81/500, 106.021}, {1/5,108.966}, {6/25, 117.801}, {7/25, 124.672},
{17/50, 142.342}};
data2={{3/125, 0.981672}, {9/250, 6.8717}, {27/500, 20.6151}, {7/100,26.5051},
{11/125, 36.6164}, {11/100, 48.1019}, {33/250,51.0469}, {79/500, 63.8087},
{24/125, 77.5521}, {23/100, 86.3871}};
data3={{1/1000, 0.}, {11/2500, 0.}, {11/1250, 5.89003}, {2/125,7.26437},
{1/40, 15.5104}, {17/500, 30.8245}, {13/250, 44.8624}, {7/100, 54.8755},
{41/500, 66.2629}, {27/250, 71.9566}, {33/250,78.6319}, {4/25, 97.7745},
{47/250,107.689}, {29/125, 117.212}};
Where each are Transpose[{xn,yn}]
I already tried this technique. I'm having some problems with the code there, but I doubt that's going to work.
alldata =
Join[Transpose[{ConstantArray[1, Length[x1]], x1, y1}],
Transpose[{ConstantArray[2, Length[x2]], x2, y2}],
Transpose[{ConstantArray[3, Length[x3]], x3, y3}]];
function[a_, b_, c_, d_, e_, f_] = a x + (d + e + f) (b x + c x^2);
params1 = {a, b, c, d};
params2 = {a, b, c, e};
params3 = {a, b, c, f};
fitall = NonlinearModelFit[alldata,KroneckerDelta[index - 1]*function[params1] +
KroneckerDelta[1, 2]*function[params2] + KroneckerDelta[1, 3]*function[params3],
{a, b, c, d, e, f}, x]
Which gives the rather obvious error:
NonlinearModelFit::fitc: Number of coordinates (2) is not equal to the number of variables (1). >>
A plot of the data sets and an approximate of what the end result should look like the following figure: