# Making a nonlinear fit to a set of data points [closed]

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}},
ListPlot[a0b5, PlotRange -> All]]


which produces a graph like this

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

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!

• 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[]. – J. M.'s technical difficulties Jan 6 '17 at 6:24
• @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 – Gvxfjørt Jan 6 '17 at 6:39
• 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? – J. M.'s technical difficulties Jan 6 '17 at 6:49
• 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. – Gvxfjørt Jan 6 '17 at 7:13
• You have fit a0b7 and plot a0b5 – Coolwater Jan 6 '17 at 7:16

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}},