# Finding best fit of parameters for data [closed]

Does anybody know why my model is picking the wrong values for DN & T?

• Please share the code in a code-block directly as text and not as image. Please refer to the editing-help to see how you can do this and a short look over the faq won't hurt either. – halirutan Sep 24 '16 at 14:02
• The default starting values are both 1 for T and DN. Change those to 12 and 0.11 and FindFit will converge to the correct values (although the fit isn't so hot for large values of t). – JimB Oct 1 '16 at 6:18

There are at least two reasons why the desired fit is "difficult" for this combination of curve and data.

First, the sum of squares for various values of T and DN is kinda lumpy. In the figure below the green dot is the default starting value and the red dot is the desired solution (in the sense that those values minimize the sum of squares).

sst[T_, DN_] := Total[(data[[All, 2]] - cout[1, 0.5, 0.5 T, DN, data[[All, 1]], T])^2]
Show[ContourPlot[sst[T, Exp[logDN]], {T, 0.5, 15}, {logDN, -4, 1},
PlotPoints -> 50, PlotRange -> {All, All, {0, 4}}, ContourLabels -> All,
Contours -> {0.001, 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 2, 3, 4},
FrameLabel -> (Style[#, Large, Bold] & ) /@ {"T", "Log[DN]"}],
ListPlot[{{{12.8369, Log[0.0799443]}}, {{1, 0}}},
PlotStyle -> {{Red, PointSize[0.02]}, {Green, PointSize[0.02]}}]]


Second choosing starting values closer to the final solution helps. ("One can't beat good starting values.") If one uses what you tried in your question (T = 12 and DN = 0.11), then the desired solution is found.

FindFit[data, cout[1, 0.5, 0.5 T, DN, t, T], {{T, 12}, {DN, 0.11}}, t]
(* {T -> 12.836895298848031,DN -> 0.07994429793304991} *)