So, I'm fairly new to Mathematica (apologies in advance for the noobiness), and I'm having some problems regarding fitting the parameters of a user defined function to data. I'll give a representative toy example of what I'm trying to accomplish.
Imagine that I have data that is comprised of two lists:
TestData = {
{1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15},
{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
};
And I have a model/function that itself produces discrete data such as this. This function would be something like:
TestFunction[A_, B_] :=
Module[{results = {}, vec1 = {}, vec2 = {}},
For[i = 1, i < 18, i++, Do;
[vec1 = Append[vec1, (A - i)];
vec2 = Append[vec2, (B + i)]]];
results = Append[results, vec1];
results = Append[results, vec2];
results]
Now, I want to find the parameters A and B that give the best approximation to TestData (i.e., such as the distance between TestData and the results of the function would be minimized).
I tried looking into the FindFit and NonlinearModelFit functions, but these would seem to be more suited for continuous functions(?), so I'm not sure how to use it with a function that returns specific and discrete values. How would you go about solving this question?
Thank you very much in advance.
TestFunction
is not working for me. $\endgroup$FindFit
/NonlinearModelFit
are usable for this. They don't intrinsically care if the function is continuous or discrete, as they only evaluate it at the abscissae you give in your data. $\endgroup$testF[a_, b_] := {Table[a - i, {i, 17}], Table[b + i, {i, 17}]}
, which both faster and simpler. $\endgroup$