# finding fit for data

How to fit this data with the best formula

dataskmc2 = {{9.65827, 0.551402}, {10.2803, 0.602804}, {11.4566,
0.953271}, {12.6648, 1.3972}, {13.8468, 1.13551}, {15.0618,
0.845794}, {16.1433, 0.817757}, {17.4852, 0.981308}, {18.6631,
1.15888}, {19.8432, 1.09813}, {21.057, 0.943925}, {22.368,
0.897196}, {23.7759, 1.00467}, {24.8564, 1.08879}}


I can not guess any function to fit.

• see LinearModelFit , NonLinearModelFit – george2079 Oct 19 '17 at 20:33

## 2 Answers

dataskmc2 = {{9.65827, 0.551402}, {10.2803, 0.602804}, {11.4566,
0.953271}, {12.6648, 1.3972}, {13.8468, 1.13551}, {15.0618,
0.845794}, {16.1433, 0.817757}, {17.4852, 0.981308}, {18.6631,
1.15888}, {19.8432, 1.09813}, {21.057, 0.943925}, {22.368,
0.897196}, {23.7759, 1.00467}, {24.8564, 1.08879}};


The best formula would be based on a theoretical model of the process generating the data. Absent any insight, the data visually appears to be a damped sinusoid on a linear ramp.

nlm = NonlinearModelFit[
dataskmc2, Exp[-a*x + b]*Sin[c*x + d] + e*x + f, {a, b, c, d, e, f}, x];

{xmin, xmax} = MinMax[dataskmc2[[All, 1]]];

nlm["BestFit"]

(* 1.01481 - 0.000669085 x + E^(0.421527 - 0.118966 x) Sin[0.62407 + 1.04152 x] *)

Plot[nlm["BestFit"], {x, xmin, xmax},
Epilog -> {Red, AbsolutePointSize[4], Point[dataskmc2]}]


As Bob Hanlon said, you should fit a theoretical model to your data. But there are cases in which there is no such model or it is not important. Bob Hanlon has a good eye, but Mathematica can also take care of this: There is this funny function FindFormula.

FindFormula[dataskmc2, x, 1, PerformanceGoal -> "Quality" ,
SpecificityGoal -> "High", TargetFunctions -> All, "RandomSeed" -> 558]
(*0.686988 - 0.00954655 x + 0.120458 Cos[x] -
0.214886 Cos[0.997167 x^0.506529 + x] + 0.178948 Log[-2. + x] +
0.225503 Sin[x] *)


The output varies with the choice of parameters and the random seed, but typically it's pretty good! Sometimes it will find very simple expressions which you would not come up with!

• I'd be really impressed if it found Bob's solution ! – george2079 Oct 20 '17 at 22:02
• In version 11.2, the option is RandomSeeding vice "RandomSeed" and the result changes to 0.6393926995143122 + (1.0015608385696102* Cos[0.9788308481646927*x])/ x^0.5005959760802368 + 0.12383633043446876*Log[x] – Bob Hanlon Oct 21 '17 at 14:29