I have the following data, i.e. a list of points:
data = {{2.4304509797414493`,
6.729260872150955`}, {2.415783210264611`,
6.565682138556903`}, {2.4285129031030896`,
6.360986237044105`}, {2.430562993364792`,
6.217242963838571`}, {2.433939194759898`,
6.000904926489934`}, {2.439798201319317`,
6.02056869053287`}, {2.4474754678928474`,
5.933316971617399`}, {2.44262947185293`,
5.7946089613451`}, {2.4363589182216328`,
5.612020534793792`}, {2.4537323675072766`,
5.497306106602562`}, {2.4569372953446074`,
5.386651172652806`}, {2.4627461665071477`,
5.030299171261363`}, {2.4589758499134926`,
4.900876752643637`}, {2.4691747688901677`,
4.76514655355153`}, {2.4588829440844933`,
4.599178719008849`}, {2.4601447061957553`,
4.681674971543597`}, {2.4620538137371892`,
4.518731147262657`}, {2.471519575080883`,
4.4887156063235185`}, {2.4833105962333133`,
4.494324100614184`}, {2.482217736826656`,
4.35346623855313`}, {2.4825618294063685`,
4.220142948899261`}, {2.493987372063851`,
4.18094620015567`}, {2.477097925380988`,
4.15283186569182`}, {2.4938992549400973`,
4.099098326478774`}, {2.497698067673524`,
3.9815629377573485`}, {2.5041350123222705`,
3.931932456990258`}, {2.4980391049582384`,
3.936625697225489`}, {2.5070860043626246`,
3.88517474618616`}, {2.5066365099981907`,
3.8705817019895843`}, {2.506883708850762`,
3.9637220751508466`}, {2.5173883296281137`,
3.965338924501667`}, {2.5203532671356474`,
4.04876386601876`}, {2.5231902325699935`,
4.137223671828706`}, {2.5139949793472285`,
4.273691499948905`}, {2.5192956267860365`,
4.3969119471631695`}, {2.5226645695039496`,
4.439285086259388`}, {2.5383526343046885`,
4.490749717622663`}, {2.538466860171095`,
4.643216483003511`}, {2.52984888069124`,
4.779386383817692`}, {2.5420446701865655`,
4.936902296968895`}, {2.5448069142094867`,
5.074772262845685`}, {2.544654259360489`,
5.207127340974729`}, {2.5408247460793305`,
5.3047205272804785`}, {2.5560437914870566`,
5.460443294447049`}, {2.544579158127718`,
5.6194936731428635`}, {2.556227507593902`,
5.7812272087171666`}, {2.5508346564146875`,
5.894824642390141`}, {2.562190730269429`,
6.114712245973943`}, {2.561307773622258`,
6.296337290605692`}, {2.573188403870403`,
6.441990229058111`}, {2.5787706742188594`,
6.623612891925203`}, {2.5690015557201415`,
6.655875936289631`}, {2.5829752008946647`,
6.703907351725054`}, {2.582218719686103`,
6.840545179753442`}, {2.575039020572967`,
7.001443162050621`}, {2.5822008893060344`,
7.002078088653101`}, {2.5812284248390114`,
7.139306108382944`}, {2.5949647014605293`,
7.216437578232519`}, {2.589591061915744`,
7.295474466371815`}, {2.594889555173271`,
7.244851925938778`}, {2.605589523411269`,
7.324236749153339`}, {2.608225581855298`,
7.385366871530149`}, {2.6027259153992657`,
7.36212645925139`}, {2.6090029464931024`,
7.401851778950361`}, {2.6218295646925274`,
7.401182407283057`}, {2.6164487196673223`,
7.3458824743549265`}, {2.6094479040052883`,
7.199953825056011`}, {2.6211773871206083`,
7.167729106856195`}, {2.63264512243632`,
7.022429199828518`}, {2.6237439115525603`,
7.045145997613185`}, {2.6324766606723915`,
7.00066515585204`}, {2.63750228225642`,
6.93478482095497`}, {2.634738772909267`,
6.893690921643136`}, {2.644149541353371`,
6.864219856346318`}, {2.6424065997768897`,
6.83027937856814`}, {2.6501323010954705`,
6.628512930884991`}, {2.6452089091628226`,
6.582296163486687`}, {2.6583652683920556`,
6.43362970520658`}, {2.646267706399761`,
6.429593966187606`}, {2.656578594618857`,
6.345478121237732`}, {2.6562868790451057`,
6.1310366943292856`}, {2.6586865341515735`,
6.1068907215880746`}, {2.6622125779486487`,
5.886500137006599`}, {2.6665120396783655`,
5.812510321428766`}, {2.673863355938594`,
5.786625409410042`}, {2.667217252357143`,
5.58886857056124`}, {2.673860783217352`,
5.601011200079617`}, {2.678930403264612`,
5.485468961983902`}, {2.68608290551096`,
5.429617344097778`}, {2.67958293086715`,
5.458867686446765`}, {2.6923527272114702`,
5.422414013774456`}, {2.6961279322800076`,
5.347402233570434`}, {2.6934341401860045`,
5.219114253066407`}, {2.699106735299276`,
5.16906153861877`}, {2.697715518005347`,
5.228710625224765`}, {2.699208698684565`,
5.16361871787311`}, {2.7100394653088937`,
5.17386428163147`}, {2.7209106937110836`, 5.093924058102383`}};
How do I obtain an explicit and elementary function that "best" fits such data? It should also be a combination of functions, let's say: Cos, Sin, Log, Times, Plus.
One idea is to have Mathematica search a great number of functions and minimise the residuals.
In the documentation I found this:
fit = FindFormula[data, x, 100000, {"Complexity",
"Error","Score"},TimeConstraint -> 100, PerformanceGoal -> "Quality",
SpecificityGoal -> 1, TargetFunctions -> {Cos, Log, Times, Plus}];
So I fixed a tolerance value
TOL = 0.5;
and tried to plot the fitting funtions in increasing order of "accuracy", relying on the "error".
errors = Select[fit[[All, 2, 2]],# < TOL &];
POS = Flatten[
Position[errors,(Sort@errors)[[#]]]&/@Range@(Length@errors), 2];
bestfits = fit[[POS,1]];
plotdata = ListPlot[data];
GraphicsRow[Show[{plotdata,Plot[bestfits[[#]], {x, 1, 1000}]},
ImageSize -> Medium]& /@POS ]
But it does not even look like a fit.
Moreover, is there a way to work with parameters?
I might be interested in obtaining a function (of x) a particular form, like
a Log[x] + b Cos[c x] Sin[x/d] - e.
{x, 1, 1000}
to the Plot instead ofdata[[;;,1]]
as thex
values ? Did you first just try usingFindFormula[data, x]
? That gives a nice cosine curve... $\endgroup$