1
$\begingroup$

This question already has an answer here:

I have a set of data (Datax for x-axis and Datay for y-axes) to fit to a sigmoidal function (Hill type). While Origin gives me the right answer, Mathematica does not. The fit values given by Origin are the one used as initial values here.

Datax = {16.58, 24.87, 33.16, 41.45, 49.74, 58.03, 66.32,
   74.61, 82.9, 91.19, 99.48, 107.77, 116.06, 124.35, 132.64,
   140.93, 149.22, 157.511, 165.801, 174.091, 182.381, 190.671,
    198.961, 207.251, 215.541, 223.831, 232.121, 240.411,
   248.701, 256.991, 265.281, 273.571, 281.861, 290.151,
   298.441, 306.731, 315.021, 323.311, 331.601, 339.891,
   348.181, 356.471, 364.761, 373.051, 381.341, 389.631,
   397.921, 406.211, 414.501, 422.791, 431.081, 439.371,
   447.661, 455.951, 464.241, 472.531, 480.821, 489.111,
   497.401, 505.691, 513.981, 522.271, 530.561, 538.851,
   547.141, 555.431, 563.721, 572.011, 580.301, 588.591,
   596.881, 605.171, 613.461, 621.751, 630.041, 638.331,
   646.621, 654.911, 663.201};

Datay = {0.0997536945812803, 0.203201970443351, 0.44088669950739,
   0.586206896551721, 0.83682266009852, 1.28571428571429,
   1.74322660098522, 1.81588669950739, 2.43411330049261,
   2.73275862068961, 3.52770935960591, 4.65517241379311,
   5.32142857142861, 6.58251231527091, 7.69211822660101,
   8.61268472906401, 10.0018472906404, 11.6594827586207,
   13.5948275862069, 15.6650246305419, 18.1305418719212,
   21.3294334975369, 24.0849753694581, 25.7629310344828,
   28.6607142857143, 32.8029556650246, 37.1804187192118,
   38.4094827586207, 41.9168719211823, 46.3737684729064,
   49.5055418719212, 51.7210591133005, 56.4002463054187,
   58.8479064039409, 61.4217980295566, 64.875, 68.8830049261084,
   68.6551724137931, 72.4519704433497, 75.368842364532,
   77.6711822660098, 80.5431034482758, 82.5960591133005,
   83.8990147783251, 84.0160098522167, 88.7543103448276,
   88.0067733990148, 90.9445812807882, 92.2259852216747,
   93.3645320197047, 92.0492610837438, 94.5628078817737,
   96.1465517241377, 95.6323891625617, 95.7820197044337,
   96.2561576354677, 97.9519704433497, 98.5554187192117,
   98.7709359605907, 98.6059113300497, 100.350369458128,
   102.073891625616, 100.54433497537, 101.966133004926,
   102.009236453202, 101.910714285715, 102.631157635468,
   101.394088669951, 103.059113300493, 100.043719211823,
   101.985837438424, 103.685344827586, 103.548645320197,
   101.98275862069, 102.926724137931, 103.96921182266,
   102.599137931035, 103.060960591133, 102.466133004926};

p1 = ListPlot[Table[{Datax[[n]], Datay[[n]]}, {n, Length[Datax]}],
  PlotStyle -> Red];

FindFit[Datay, v x^n/(a^n + x^n), {{n, 3.9}, {a, 234}, {v, 108}}, x ,
 MaxIterations -> 1000]

p2 = Plot[{108 x^3.9/(234^3.9 + x^3.9), 108 x^3.8/(32^3.8 + x^3.8)}, {x, 0, 800}];

Show[p2, p1]

enter image description here

Has someone some ideas why that?

$\endgroup$

marked as duplicate by Feyre, corey979, MarcoB, m_goldberg, gwr Mar 2 '17 at 19:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ I'm guessing the answer is correct. YOu're not including x-values in your FindFit, so MMA assumes integers... $\endgroup$ – tkott Mar 24 '15 at 14:48
4
$\begingroup$

You're only providing y-values to FindFit, with so Mathematica has no knowledge of the x-values and has to assume them to be integers starting from 1.

You can change this by doing xydata = Transpose[{Datax, Datay}] to generate a list of x-y pairs for the model to fit to.

The fitting can then be carried out as before:

xydata = Transpose[{Datax, Datay}];
model = v x^n/(a^n + x^n);

result = FindFit[xydata, model, {{n, 3.9}, {a, 234}, {v, 108}}, x]

p1 = ListPlot[xydata, PlotStyle -> Red];
p2 = Plot[model /. result, {x, 0, 800}];
Show[p2, p1]

which gives the following fit:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ You might want to point out what the OP was doing wrong, specifically the lack of use of the x-data such that mathematica was assuming x values... $\endgroup$ – tkott Mar 24 '15 at 14:50
  • $\begingroup$ @tkott sorry yes, was in the middle of editing! $\endgroup$ – dr.blochwave Mar 24 '15 at 14:51
  • $\begingroup$ Thanks guys, obviously I was so stupid...sorry :) $\endgroup$ – adras81 Mar 24 '15 at 15:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.