0
$\begingroup$

Consider the following dataset:

dataTest = {{0.14453526110630593, 0.7014904848670585}, {0.1734422786434469, 0.7024964901427895}, {0.2023493539874549, 0.7043948863409647}, 
 {0.23125637152459588, 0.7058338203874175}, {0.2601634468686039, 0.7069684288109898}, {0.2890704644057448, 0.7078906354037657}, 
 {0.31797753974975285, 0.7086321510699408}, {0.3468845572868938, 0.7092598303945684}, {0.37579163263090176, 0.7098016543144797}, 
 {0.40469865016804274, 0.7102756059691135}, {0.4336057255120508, 0.7106967838592871}, {0.46251274304919177, 0.7110243671945703}, 
 {0.4914198183931997, 0.7113165801024204}, {0.5203268359303407, 0.7115807648289797}, {0.5492339112743487, 0.7118211101923126}, 
 {0.5781409288114896, 0.7120412229188238}, {0.6070478307348965, 0.7122334937863117}, {0.6359553107269738, 0.7123931746470176}, 
 {0.6648622126503807, 0.7125394918690394}, {0.6937691145737876, 0.712675323134136}, {0.7226760164971945, 0.7128012531543533}, 
 {0.7515834964892716, 0.7129102731184883}, {0.7804903984126785, 0.7130084563017882}, {0.8093973003360855, 0.7131013135078462}, 
 {0.8383042022594924, 0.7131890880162225}, {0.8672116822515696, 0.7132734530539421}, {0.8961185841749766, 0.7133426791831213}, 
 {0.9250254860983835, 0.7134089754433968}, {0.9539323880217904, 0.7134734652520198}, {0.9828398680138675, 0.7135368750758726}, 
 {1.0117467699372744, 0.7135988002843787}, {1.0406536718606814, 0.7136512720709652}, {1.0695605737840883, 0.7136978256021405}, 
 {1.0984680537761655, 0.7137448805190238}, {1.1273749556995725, 0.7137919451322199}, {1.1562818576229792, 0.7138393121597663}, 
 {1.1851887595463864, 0.7138803954279481}, {1.2140962395384634, 0.7139161188005846}, {1.2430031414618705, 0.7139523199843658}, 
 {1.2719100433852772, 0.713989603945575}, {1.3008169453086842, 0.714027986771783}, {1.3297244253007614, 0.7140612471534088}, 
 {1.3586313272241681, 0.714089321031941}, {1.3875382291475753, 0.7141190813825439}, {1.416445131070982, 0.7141497995615563}, 
 {1.445352611063059, 0.7141826095767434}, {1.4742595129864662, 0.7142086788394784}, {1.5031664149098731, 0.7142327827707194}, 
 {1.53207331683328, 0.7142579817598341}, {1.560980796825357, 0.7142849966046831}, {1.5898876987487642, 0.7143128075218439}, 
 {1.618794600672171, 0.7143343838677734}, {1.647701502595578, 0.7143554345245029}, {1.6766089825876551, 0.7143779235379654}, 
 {1.7055158845110618, 0.7144012704460995}, {1.734422786434469, 0.7144258019677487}, {1.7633296883578757, 0.7144444315699745}, 
 {1.7922371683499532, 0.7144635046936838}, {1.82114407027336, 0.7144832740859485}, {1.850050972196767, 0.7145039530404097}, 
 {1.8789578741201738, 0.7145255613952877}, {1.9078653541122508, 0.7145443892086003}, {1.936772256035658, 0.7145612236249971}, 
 {1.9656791579590647, 0.7145786728406864}, {1.9945860598824718, 0.7145967842690146}, {2.023493539874549, 0.7146157494478557}, 
 {2.052400441797956, 0.7146326147018904}, {2.0813073437213627, 0.714648246227177}, {2.11021424564477, 0.7146642489550049}, 
 {2.139121725636847, 0.7146808438978467}, {2.1680286275602536, 0.7146975668760922}, {2.1969355294836608, 0.7147131532495594}, 
 {2.2258424314070675, 0.7147278572636038}, {2.254749911399145, 0.7147428880565225}, {2.2836568133225517, 0.714757815610317}, 
 {2.3125637152459584, 0.7147728116200549}, {2.3414706171693656, 0.7147869834644986}, {2.370378097161443, 0.7148012382865211}, 
 {2.3992849990848497, 0.7148151167234148}, {2.4281919010082564, 0.7148288765567858}, {2.457098802931663, 0.7148424045888571}, 
 {2.486006282923741, 0.7148563861039867}, {2.5149131848471478, 0.7148696942510752}, {2.5438200867705545, 0.714882605734823}, 
 {2.572726988693961, 0.714895189936785}, {2.601634468686038, 0.7149073213299418}, {2.630541370609446, 0.7149200229716947}, 
 {2.6594482725328525, 0.7149330005514021}, {2.6883551744562593, 0.7149453738973215}, {2.7172626544483363, 0.7149573475187669}, 
 {2.746169556371744, 0.7149683001954984}, {2.7750764582951506, 0.7149811938714392}, {2.8039833602185573, 0.714993615267197}, 
 {2.8328908402106343, 0.7150052877191962}, {2.861797742134041, 0.715015978118395}, {2.8907046440574486, 0.7150256258416336}, 
 {2.9196115459808554, 0.7150374852924305}, {2.9485190259729324, 0.7150497575946416}, {2.977425927896339, 0.7150609625571394}, 
 {3.0063328298197463, 0.7150711553656104}, {3.0352397317431534, 0.7150800992353935}, {3.0641472117352304, 0.7150911423903978}, 
 {3.093054113658637, 0.7151031317276138}, {3.121961015582044, 0.7151138930035509}, {3.150867917505451, 0.715123576057336}, 
 {3.1797753974975285, 0.715131819259456}, {3.208682299420935, 0.715143511364696}, {3.237589201344342, 0.7151550896018745}, 
 {3.2664961032677486, 0.7151652311449493}, {3.2954035832598265, 0.7151740964547794}, {3.3243104851832332, 0.7151812298812275}, 
 {3.35321738710664, 0.7151916437390736}, {3.3821242890300467, 0.7152032227385715}, {3.4110317690221237, 0.7152134163001265}, 
 {3.4399386709455313, 0.7152218680383986}, {3.468845572868938, 0.7152285494151239}, {3.4977524747923447, 0.7152402696464555}, 
 {3.5266599547844217, 0.7152514428199225}, {3.5555668567078293, 0.7152608222456264}, {3.584473758631236, 0.7152683635900813}, 
 {3.613380660554643, 0.7152739717657457}, {3.64228814054672, 0.7152865284548114}, {3.6711950424701265, 0.7152972479255991}, 
 {3.700101944393534, 0.715306108396503}, {3.729008846316941, 0.7153130104661517}, {3.757916326309018, 0.7153178641252946}, 
 {3.7868232282324246, 0.7153265858096199}, {3.8157301301558317, 0.7153379701040616}, {3.844637032079239, 0.7153473909908408}, 
 {3.873544512071316, 0.7153548873248294}, {3.9024514139947226, 0.7153600121337386}, {3.9313583159181293, 0.7153700392137192}, 
 {3.9602652178415365, 0.7153808920424357}, {3.989172697833614, 0.715389791183155}, {4.01807959975702, 0.715396365442883}, 
 {4.046986501680427, 0.7154004939191148}, {4.075893403603835, 0.7154094289303038}, {4.104800883595912, 0.7154206564905599}, 
 {4.133707785519318, 0.7154295898039698}, {4.1626146874427254, 0.7154362036437029}, {4.191521589366133, 0.7154402901872312}, 
 {4.22042906935821, 0.7154505084530111}, {4.249335971281616, 0.7154611233649515}, {4.2782428732050235, 0.7154694225380247}, 
 {4.30714977512843, 0.7154752224765358}, {4.336057255120507, 0.7154784026606696}, {4.364964157043914, 0.7154874675588563}, 
 {4.3938710589673216, 0.7154983382141613}, {4.422777960890728, 0.715506804462821}, {4.451685440882805, 0.7155128391998571}, 
 {4.480592342806212, 0.7155159369210695}, {4.50949924472962, 0.7155237382498447}, {4.538406146653026, 0.7155348164409014}, 
 {4.567313626645103, 0.7155434979305474}, {4.5962205285685105, 0.7155494540532984}, {4.625127430491917, 0.715552528796367}, 
 {4.654034332415324, 0.7155594454835523}, {4.682941812407401, 0.7155704919558988}, {4.7118487143308085, 0.7155789158388652}, 
 {4.740755616254215, 0.7155845765732505}, {4.769662518177622, 0.7155872658847064}, {4.798569998169699, 0.7155951166923541}, 
 {4.827476900093106, 0.7156059911386513}, {4.856383802016513, 0.7156141262145517}, {4.88529070393992, 0.7156194146901577}, 
 {4.9141981839319975, 0.7156217438865576}, {4.943105085855404, 0.7156310735678816}, {4.972011987778811, 0.7156417315785409}, 
 {5.000918889702218, 0.7156496134105431}, {5.0298263696942955, 0.7156545864161721}, {5.058733271617702, 0.7156562713163669}, 
 {5.087640173541109, 0.7156618505936194}, {5.116547075464515, 0.7156729460695415}, {5.145454555456594, 0.7156812782895065}, 
 {5.17436145738, 0.7156864702774149}, {5.203268359303407, 0.7156883953552746}, {5.232175261226813, 0.7156953603583189}, 
 {5.261082741218892, 0.7157062107264935}, {5.289989643142298, 0.7157140361495966}, {5.318896545065705, 0.7157187016338326}, 
 {5.347803446989111, 0.7157199816918752}, {5.37671092698119, 0.7157282712920705}, {5.405617828904596, 0.7157388667584941}, 
 {5.434524730828003, 0.7157464214094048}, {5.463431632751409, 0.7157507159094425}, {5.492339112743488, 0.7157515929660119}, 
 {5.521246014666894, 0.7157617459372847}, {5.550152916590301, 0.7157720003652603}, {5.5790598185137075, 0.7157791471687294}, 
 {5.607967298505784, 0.7157829814499455}, {5.636874200429192, 0.7157831358877771}, {5.665781102352599, 0.7157891415671526}, 
 {5.6946880042760055, 0.715799898052269}, {5.723595484268082, 0.7158075879325976}, {5.75250238619149, 0.715811790647168}, 
 {5.781409288114897, 0.7158123485951571}, {5.810318502312984, 0.7158202346703884}, {5.83922193582437, 0.7158304953712515}, 
 {5.8681311500224576, 0.7158382288328914}, {5.897040364220546, 0.7158424507152038}, {5.9259437977319305, 0.7158422698679237}, 
 {5.954853011930019, 0.7158529053592377}, {5.983756445441405, 0.7158624522646301}, {6.0126656596394925, 0.7158693027544211}, 
 {6.04157487383758, 0.7158725503024848}, {6.070478307348965, 0.7158712186147586}, {6.099387521547054, 0.7158782645223238}, 
 {6.128296735745142, 0.7158892466786028}, {6.157200169256527, 0.7158962226249505}, {6.186109383454615, 0.7159002491249564}, 
 {6.215012816966001, 0.715899685596395}, {6.243922031164088, 0.7159070540586366}, {6.272831245362176, 0.7159180082466092}, 
 {6.3017346788735615, 0.7159247922534006}, {6.33064389307165, 0.715928572636798}, {6.359553107269737, 0.7159283732563396}, 
 {6.388456540781123, 0.7159365941352872}, {6.417365754979211, 0.7159471891571912}, {6.446269188490596, 0.7159536435299938}, 
 {6.475178402688684, 0.7159569212305839}, {6.504087616886772, 0.7159561570409314}, {6.532991050398158, 0.7159617258793478}, 
 {6.561900264596245, 0.7159728357966408}, {6.590809478794333, 0.7159804800169433}, {6.619712912305719, 0.7159835816247629}, 
 {6.648622126503807, 0.7159832404385726}, {6.677525560015192, 0.7159895624857111}, {6.70643477421328, 0.7160005052938005}, 
 {6.735343988411368, 0.7160078263120289}, {6.764247421922754, 0.7160106299523072}, {6.793156636120841, 0.7160098595507051}, 
 {6.822065850318929, 0.7160177315394555}, {6.850969283830315, 0.7160278614269266}, {6.879878498028403, 0.7160349016163154}, 
 {6.908781931539788, 0.7160373548412576}, {6.937691145737876, 0.7160361445185683}, {6.966600359935964, 0.716044853174747}, 
 {6.995503793447349, 0.7160548149007658}, {7.024413007645437, 0.7160616105358388}, {7.0533222218435245, 0.7160643471100383}, 
 {7.082225655354911, 0.7160621350429457}, {7.1111348695529975, 0.7160684432274498}, {7.140038303064384, 0.7160790341937384}, 
 {7.168947517262472, 0.716086414466562}, {7.1978567314605595, 0.7160897231205003}, {7.226760164971945, 0.7160880838653294}, 
 {7.255669379170033, 0.7160936779719357}, {7.284578593368121, 0.7161049228778374}, {7.313482026879506, 0.7161117565887789}, 
 {7.3423912410775936, 0.7161150448511493}, {7.37129467458898, 0.7161133259936822}, {7.400203888787068, 0.7161206499581467}, 
 {7.429113102985156, 0.7161314827443513}, {7.458016536496541, 0.716137827691745}, {7.4869257506946285, 0.7161405375036951}, 
 {7.515834964892717, 0.716138717343906}, {7.544738398404101, 0.716143699111081}, {7.57364761260219, 0.7161550598624493}, 
 {7.602551046113576, 0.7161619436107741}, {7.6314602603116635, 0.7161651447548614}, {7.660369474509751, 0.7161638241166999}, 
 {7.689272908021136, 0.7161698734157417}, {7.718182122219225, 0.7161808622402924}, {7.747091336417313, 0.7161878350720648}, 
 {7.7759947699286975, 0.7161899902629362}, {7.804903984126786, 0.7161880373303906}, {7.833807417638172, 0.7161947238394651}, 
 {7.862716631836259, 0.7162057295297988}, {7.891625846034347, 0.7162126518125466}, {7.9205292795457325, 0.716214671189607}, 
 {7.949438493743821, 0.7162125568422572}, {7.978347707941908, 0.7162179763599276}, {8.007251141453294, 0.7162286707119913}, 
 {8.036160355651381, 0.7162358059354066}, {8.065063789162767, 0.7162379905352283}, {8.093973003360855, 0.7162360007472287}, 
 {8.122882217558942, 0.7162423425077765}, {8.151785651070329, 0.7162530208435431}, {8.180694865268418, 0.7162600437990676}, 
 {8.209604079466503, 0.7162626553445602}, {8.23850751297789, 0.7162599267646308}, {8.267416727175977, 0.7162663658374607}, 
 {8.296320160687364, 0.7162769230164296}, {8.325229374885451, 0.7162837741429029}, {8.354138589083538, 0.7162860986893552}, 
 {8.383042022594925, 0.71628305853723}, {8.411951236793012, 0.716288442213056}, {8.4408604509911, 0.7162999520327825}, 
 {8.469763884502486, 0.7163067620950265}, {8.498673098700573, 0.716309512069283}, {8.52757653221196, 0.716306894699049}, 
 {8.556485746410047, 0.7163121196645202}, {8.585394960608134, 0.7163233660918591}, {8.614298394119519, 0.7163298505968675}, 
 {8.643207608317608, 0.7163322086836343}, {8.672116822515695, 0.7163296092178374}, {8.701020256027082, 0.7163355382367962}, 
 {8.72992947022517, 0.7163467526515032}, {8.758832903736554, 0.7163531720328202}, {8.787742117934643, 0.7163553985677893}, 
 {8.81665133213273, 0.7163525990430009}, {8.845554765644115, 0.7163574192573414}, {8.874463979842204, 0.7163690320437537}, 
 {8.903373194040292, 0.7163763068796672}, {8.932276627551678, 0.7163784262015178}, {8.961185841749765, 0.7163759555005255}, 
 {8.99008927526115, 0.7163803184413675}, {9.01899848945924, 0.7163917534454249}, {9.047907703657327, 0.7163987678287629}, 
 {9.076811137168711, 0.7164005981587956}, {9.1057203513668, 0.7163977750326805}, {9.134629565564888, 0.7164040995196427}, 
 {9.163532999076272, 0.7164151532804522}, {9.192442213274362, 0.7164222167083303}, {9.221345646785746, 0.7164240383686177}, 
 {9.250254860983834, 0.7164211756654361}, {9.279164075181923, 0.7164244701182247}, {9.308067508693307, 0.7164355689987013}, 
 {9.336976722891396, 0.7164426618941171}, {9.365885937089484, 0.71644489583095}, {9.39478937060087, 0.7164415147150873}, 
 {9.423698584798958, 0.716445398304912}, {9.452602018310342, 0.716457009047511}, {9.48151123250843, 0.7164646049408805}, 
 {9.510420446706517, 0.7164673431925135}, {9.539323880217903, 0.7164644709225316}, {9.568233094415993, 0.7164696791828764}, 
 {9.59714230861408, 0.7164814565477384}, {9.626045742125466, 0.7164882529146255}, {9.654954956323552, 0.716490590450396}, 
 {9.683858389834938, 0.716487224608316}, {9.712767604033026, 0.716490365901681}, {9.741676818231113, 0.7165021068766879}, 
 {9.7705802517425, 0.716508821040384}, {9.799489465940589, 0.7165110177697117}, {9.828398680138676, 0.7165078660802437}, 
 {9.857302113650059, 0.7165131637161312}, {9.886211327848148, 0.7165247509201323}, {9.915114761359535, 0.7165312320045916}, 
 {9.944023975557622, 0.716533152270636}, {9.97293318975571, 0.716529685041784}, {10.001836623267096, 0.7165341421090944}, 
 {10.030745837465183, 0.7165461679425389}, {10.059655051663272, 0.7165535433664335}, {10.088558485174655, 0.7165555056695285}, 
 {10.117467699372744, 0.7165524841206319}, {10.14637113288413, 0.7165544451651233}, {10.175280347082218, 0.7165662758368821}, 
 {10.204189561280305, 0.716573409435052}, {10.233092994791692, 0.7165750774618744}, {10.262002208989779, 0.7165717024290134}, 
 {10.290911423187868, 0.7165772394489387}, {10.319814856699251, 0.71658863269898}, {10.34872407089734, 0.716595674953595}, 
 {10.377627504408725, 0.7165971928957307}, {10.406536718606814, 0.7165936084320254}, {10.435445932804901, 0.7165978250620675}, 
 {10.464349366316288, 0.7166092730260454}, {10.493258580514375, 0.7166163236354555}, {10.522167794712463, 0.7166182450373143}, 
 {10.551071228223847, 0.7166142099671453}, {10.579980442421936, 0.7166089702343762}, {10.608883875933321, 0.7166225927176914}, 
 {10.63779309013141, 0.7166319731855044}, {10.666702304329498, 0.7166363446359136}, {10.695605737840884, 0.7166349367019591}, 
 {10.724514952038971, 0.7166397517507153}, {10.753424166237059, 0.7166516599914307}, {10.782327599748443, 0.7166583255407704}, 
 {10.811236813946532, 0.7166601585386873}, {10.840140247457917, 0.7166559726286994}, {10.869049461656006, 0.7166597885619646}, 
 {10.897958675854094, 0.7166717661156327}, {10.92686210936548, 0.7166784788049316}, {10.955771323563566, 0.7166803191090794}, 
 {10.984680537761653, 0.7166764995214397}, {11.01358397127304, 0.7166738371996277}, {11.042493185471129, 0.716687360110058}, 
 {11.071396618982513, 0.7166956716015542}, {11.100305833180602, 0.7166992236169606}, {11.12921504737869, 0.7166971837678429}, 
 {11.158118480890074, 0.7167017763587149}, {11.187027695088162, 0.7167138982691537}, {11.215936909286249, 0.7167210689089341}, 
 {11.244840342797636, 0.7167225358278879}, {11.273749556995723, 0.7167186622066063}, {11.30265299050711, 0.7167215777215791}, 
 {11.331562204705198, 0.7167335204076274}, {11.360471418903286, 0.7167404756315904}, {11.38937485241467, 0.7167416867094915}, 
 {11.418284066612758, 0.716737456559151}, {11.447193280810845, 0.7167382793756001}, {11.476096714322232, 0.7167507361326414}, 
 {11.505005928520319, 0.7167586082627747}, {11.533909362031705, 0.716760745806242}, {11.562818576229795, 0.7167575159827063}, 
 {11.591727790427882, 0.7167633985088556}, {11.620631223939265, 0.7167747890807455}, {11.649540438137354, 0.7167814684759725}, 
 {11.678449652335441, 0.7167826843763314}, {11.707353085846828, 0.7167776557648993}, {11.736262300044915, 0.7167829414103439}, 
 {11.765165733556302, 0.7167945017136633}, {11.794074947754389, 0.7168013326226798}, {11.822984161952476, 0.7168026660902779}, 
 {11.851887595463861, 0.7167977462303528}, {11.88079680966195, 0.7167950119899161}, {11.909706023860037, 0.7168085083133121}, 
 {11.938609457371424, 0.716816654293747}, {11.967518671569511, 0.7168197537603457}, {11.996422105080898, 0.7168166958262178}, 
 {12.025331319278985, 0.7168229276949163}, {12.054240533477072, 0.7168347267339785}, {12.083143966988457, 0.7168410143927229}, 
 {12.112053181186546, 0.7168420576530677}, {12.140962395384634, 0.7168371070356203}, {12.16986582889602, 0.7168414921980372}, 
 {12.198775043094107, 0.716853264567647}, {12.227678476605494, 0.7168595112864548}, {12.25658769080358, 0.7168604884538372}, 
 {12.285496905001668, 0.7168554230577665}, {12.314400338513053, 0.7168560115535667}, {12.343309552711142, 0.7168689864502691}, 
 {12.37221876690923, 0.7168768272911489}, {12.401122200420616, 0.7168788031153337}, {12.430031414618703, 0.7168751231616141}, 
 {12.458934848130088, 0.716880436850686}, {12.487844062328175, 0.716892176273623}, {12.516753276526265, 0.7168986435691215}, 
 {12.54565671003765, 0.716899104933302}, {12.574565924235738, 0.7168937879979563}, {12.603475138433826, 0.7168986418025347}, 
 {12.632378571945212, 0.7169104842022275}, {12.6612877861433, 0.716917372426397}, {12.690191219654684, 0.7169182809094209}, 
 {12.719100433852772, 0.716913388564785}, {12.748009648050859, 0.7169170359597238}, {12.776913081562245, 0.7169287802749131}, 
 {12.805822295760334, 0.7169355562756822}, {12.834731509958422, 0.7169366085101562}, {12.863634943469808, 0.7169311750274928}, 
 {12.892544157667896, 0.716937267094808}, {12.92144759117928, 0.7169488211166184}, {12.950356805377368, 0.7169553691588012}, 
 {12.979266019575455, 0.7169561387541156}, {13.008169453086841, 0.7169503750829359}, {13.03707866728493, 0.7169541782877228}, 
 {13.065987881483018, 0.716966059172381}, {13.094891314994404, 0.7169722007029837}, {13.12380052919249, 0.7169728747537214}, 
 {13.152703962703876, 0.7169670043568517}, {13.181613176901964, 0.7169710203771286}, {13.210522391100051, 0.7169833343767102}, 
 {13.239425824611438, 0.7169899404305186}, {13.268335038809525, 0.716991064061347}};

In the first approximation, the plot of this function looks like sqrt[a+b*x]. I tried to fit the data:

nlm = NonlinearModelFit[dataTest, Sqrt[a + b*x], {a, b}, x]

But it returns

NonlinearModelFit::nrlnum: The function value {0.127405072348442538,0.114183445358926798,0.099883889415369777,0.085849589449873272,0.071915935836690437,<<42>>,-0.71423278277071947+0.50765567332310158 I,-0.71425798175983409+0.52708246980970478 I,-0.71428499660468309+0.54581863222958360 I,<<405>>} is not a list of real numbers with dimensions {455} at {a,b} = {0.78757660396955083,-0.69539265663366751}.

Could you please tell me how to fix this problem?

$\endgroup$
3
  • 2
    $\begingroup$ If you plot ListPlot[MapAt[#^2 &, dataTest, {All, 2}], PlotRange -> All], you'll notice that Sqrt[a + b*x] cannot possibly be a good fit for your data. $\endgroup$ Apr 22, 2021 at 10:13
  • 1
    $\begingroup$ What happens if you Sqrt a negative number ? You'll get an imaginary part, that's what's going on here. Add constraints: nlm = NonlinearModelFit[dataTest, {Sqrt[a + b*x], a > 0, b > 0}, {a, b}, x] or use Sqrt[Abs[a + b*x]] instead. Also what Sjoerd said - your data is basically just a flat line so this isn't going to fit. Visualize: ListPlot[dataTest, PlotRange -> {0, 1}] $\endgroup$
    – flinty
    Apr 22, 2021 at 10:14
  • $\begingroup$ Do you need to fit a simple function built out of elementary functions? Would an interpolation function, perhaps with smoothing, be adequate? You could then use this as your special function in further calculations. It would work like any other function. $\endgroup$
    – Hugh
    Apr 22, 2021 at 10:40

2 Answers 2

3
$\begingroup$

modified answer

Perhaps rational functions give a better model:

mod = NonlinearModelFit[dataTest, {(a + b x + c x^2)/(d +  x) }, {a, b, c, d}, x]
Show[{ListPlot[dataTest ],Plot[mod[x], {x, xmin, xmax} , PlotStyle -> Red]}]

enter image description here

addendum

If you don't know which modell function to use implicit fit of conic section might be useful :

var = Table[v[i], {i, 1, 5}];
fit = NonlinearModelFit[Map[{#[[1]], #[[2]], 0} &, dataTest], x^2 + {1, x, y , y^2, x y} . var, var, {x, y}]
ContourPlot[0 == fit[x, y], {x, Min[dataTest[[All, 1]]],Max[dataTest[[All, 1]]]}, {y, Min[dataTest[[All, 2]]],Max[dataTest[[All, 2]]]}, 
Epilog -> Point[dataTest],ContourStyle -> Red]

enter image description here

$\endgroup$
3
  • $\begingroup$ After using long division model could be a x + b + c/(x + d) $\endgroup$ Apr 22, 2021 at 20:29
  • $\begingroup$ I assume that you are suggesting rational functions (plural) in which the next potential model might be (a + b x + c x^2 + d x^3)/(1 + e x + f x^2). $\endgroup$
    – JimB
    Apr 23, 2021 at 3:28
  • $\begingroup$ @JimB Yes, thanks, I corrected my answer. I have added an interesting implicit fit using conic section. $\endgroup$ Apr 23, 2021 at 6:28
2
$\begingroup$

You write: "In the first approximation, the plot of this function looks like Sqrt[a+b*x]". If this were true, then the square of the y values should approx. give a straight line:

ListLinePlot[{#[[1]],#[[2]]^2}&/@dataTest]

enter image description here

Therefore, your model is useless. But how to get a better model? E.g. there is the function FindFormula that can give you an idea:

f = FindFormula[dataTest, x]
Plot[f, {x, 0, 13}, Epilog -> Point[dataTest]]

enter image description here

Note that there is a random element in FindFormula. You may eventually have to run it several times until you find an acceptable formula. Sometimes the option: SpecificityGoal -> Infinity will help.

If you finally have an acceptable approximation and you want a better fit, you can generalize the formula by introducing more parameters.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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