2
$\begingroup$

I have a collection of data

 a0b7 = 
   Table[
     {{0.01`, 0.048210580093612655`}, {0.02`, 0.04823954678734667`}, 
      {0.03`, 0.04821555471430313`}, {0.04`, 0.04811564106936836`}, 
      {0.05`, 0.04815182711185681`}, {0.06`, 0.04800244159194423`}, 
      {0.07`, 0.047987407067919395`}, {0.08`, 0.04785766284608522`}, 
      {0.09`, 0.047771957661935774`}, {0.1`, 0.04772401202975343`}, 
      {0.11`, 0.0476528836847016`}, {0.12`, 0.04757077818998488`}, 
      {0.13`, 0.04752808223718771`}, {0.14`, 0.04743123828481375`}, 
      {0.15`, 0.047472879479558236`}, {0.16`, 0.04753933712481332`}, 
      {0.17`, 0.0475047868063725`}, {0.18`, 0.04757767540247086`}, 
      {0.19`, 0.04759783119112234`}, {0.2`, 0.04756174676025805`}, 
      {0.21`, 0.04762931320390573`}}];

I'm trying to do a nonlinear fit, below is my code

a0b7model = a Exp[-b (x - c)^6] + d Sin[ω x + Φ];
a0b7fit = FindFit[a0b7, a0b7model, {a, b, c, d, ω, Φ}, x]
Show[
  Plot[Evaluate[model /. a0b7fit], {x, 0.01, 0.21}, 
    PlotStyle -> {Orange}, 
    PlotRange -> {{0, 0.21}, {0.045, 0.05}}, 
    PlotLegends -> {"7 beads"}], 
  ListPlot[a0b5, PlotRange -> All]]

which produces a graph like this

enter image description here

So, I used the initial guess of a,b,c,d,ω,Φ to substitute into the next FindFit, and I've been keep repeating this step. However, the best fit I could possibly get was

enter image description here

Which isn't even close to desired. In addition, I have tried to modify the exponential power term of the model, 6 seemed to be the best bet. Much appreciated if can get some help here!

$\endgroup$

closed as off-topic by m_goldberg, corey979, Feyre, WReach, Anton Antonov Jan 8 '17 at 16:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, corey979, Feyre, WReach, Anton Antonov
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Using the parameters found by FindFit[] as new seeds really won't do anything useful, since those parameters are a local minimum for the sum-of-squares function being optimized internally. (An analogy: consider a function with two unequal local minima, and then trying to find the lowest one by giving a starting point closer to the higher one.) You'll want to try finding better seeds even before using FindFit[]. $\endgroup$ – J. M. is away Jan 6 '17 at 6:24
  • $\begingroup$ @J.M. Thanks for pinpointing that out. Any better way to find seed than keep trying? Sorry it might be a trivial question but I'm new to this $\endgroup$ – Gvxfjørt Jan 6 '17 at 6:39
  • $\begingroup$ It's not really that trivial. Doesn't the theory behind the process that generated your data give hints on how you might be able to come up with rough seeds? $\endgroup$ – J. M. is away Jan 6 '17 at 6:49
  • $\begingroup$ unfortunately not in this case, as the data are not really sequential, each data point represents Energy computed by a parameter, since the parameters are not related to each other, neither energy should. All I'm trying to do here is to plot the best fit of each set of data and combine with other plots all in one in order to find out the intersection where the optimised parameter allocates. The seed I used in the post fitted another several sets of data really well, that's why I naïvely thought it'd also work on this set. $\endgroup$ – Gvxfjørt Jan 6 '17 at 7:13
  • $\begingroup$ You have fit a0b7 and plot a0b5 $\endgroup$ – Coolwater Jan 6 '17 at 7:16
6
$\begingroup$

There are several problems with your posted code. First, wrapping your data in Table is doing no good.

a0b7 = 
  {{0.01`, 0.048210580093612655`}, {0.02`, 0.04823954678734667`}, 
  {0.03`, 0.04821555471430313`}, {0.04`, 0.04811564106936836`}, 
  {0.05`, 0.04815182711185681`}, {0.06`, 0.04800244159194423`}, 
  {0.07`, 0.047987407067919395`}, {0.08`, 0.04785766284608522`}, 
  {0.09`, 0.047771957661935774`}, {0.1`, 0.04772401202975343`}, 
  {0.11`, 0.0476528836847016`}, {0.12`, 0.04757077818998488`}, 
  {0.13`, 0.04752808223718771`}, {0.14`, 0.04743123828481375`}, 
  {0.15`, 0.047472879479558236`}, {0.16`, 0.04753933712481332`}, 
  {0.17`, 0.0475047868063725`}, {0.18`, 0.04757767540247086`}, 
  {0.19`, 0.04759783119112234`}, {0.2`, 0.04756174676025805`}, 
  {0.21`, 0.04762931320390573`}};

a0b7model = a Exp[-b (x - c)^6] + d Sin[ω x + Φ];
a0b7fit = FindFit[a0b7, a0b7model, {a, b, c, d, ω, Φ}, x]

FindFit::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations.

Next, Mathematica is telling you that it didn't get a good fit, but you neglected to mention this important fact. However, the fit isn't as bad as the one you show because you seemed to be confused about which model goes with which data set.

Show[
 Plot[Evaluate[a0b7model /. a0b7fit], {x, 0.01, 0.21},
  PlotStyle -> {Orange},
  PlotRange -> {{0, 0.21}, {0.045, 0.05}},
  PlotLegends -> {"7 beads"}],
 ListPlot[a0b7, PlotRange -> All]]

plot

Note that in my plot, everything is prefixed with "a0b7", but this does not hold in your posted code.

$\endgroup$
  • $\begingroup$ thanks for pinpointing it out! I guess my updated question now is, any suggestion what seed can fit it better? $\endgroup$ – Gvxfjørt Jan 6 '17 at 7:26
  • 2
    $\begingroup$ @GavyLittlewolf. Finding a better model is a math or statistics question, not a Mathematica issue. I suggest you ask on stats.SE or math.SE. $\endgroup$ – m_goldberg Jan 6 '17 at 7:29
  • $\begingroup$ I appreciate your help. I have a question in regard to your first point, you mentioned " wrapping your data in Table is doing no good." may I ask the reason why? $\endgroup$ – Gvxfjørt Jan 6 '17 at 10:06
  • 3
    $\begingroup$ @ Gavy The syntax for Table you have used is wrong. Moreover Table is mostly used for generating a list of things. Here you already have data available. So there is no need for Table. $\endgroup$ – Lotus Jan 6 '17 at 10:19

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