TransWikia.com

Using NonlinearModelFit from ParametricNDSolveValue with three parameters

Mathematica Asked by Rémy Galli on January 26, 2021

Here is the very desired Parametricfunction , calculated using ParametricNDSolve, from physical arguments.
From this, an interpolating function dens is settled.

E[CurlyPhi][[CurlyPhi]_?NumberQ, g_?NumberQ] = (
  E^[CurlyPhi] (Gamma[g] - Gamma[g, [CurlyPhi]]))/Gamma[g];

[Phi] = ParametricNDSolveValue[{(2 Derivative[1][[CurlyPhi]][x] + 
       x  ([CurlyPhi]^[Prime][Prime])[x]) == - 9 x /
       E[CurlyPhi][[Psi]0, g] (
      E^[CurlyPhi][x] (Gamma[g] - Gamma[g, [CurlyPhi][x]]))/
      Gamma[g], [CurlyPhi]'[10^-10] == 
     0 , [CurlyPhi][10^-10] == [Psi]0, 
    WhenEvent[(Re[[CurlyPhi][x]] < 
        0.015) [Or] (Im[[CurlyPhi][x]] != 0), end = x; 
     "StopIntegration"]}, [CurlyPhi], {x, 
    10^-10, +[Infinity]}, {[Psi]0, g}] ;

dens[[Psi]0_, g_, 
   x_] = (Exp[[Phi][[Psi]0, g][
       x]] (Gamma[g] - Gamma[g, [Phi][[Psi]0, g][x]])/Gamma[g])/
   E[CurlyPhi][[Psi]0, g];

Here is some graphic examples .
As you can see, function dens is an interpolated function on a limited domain depending on {[Psi]0,g}.

gr1=LogLogPlot[{dens[6.4,2.3,x],dens[6.4,2.5,x],
dens[6.4,2.7,x],dens[6.4,2.9,x],dens[6.4,3.2,x],dens[6.4,3.5,x]}, 
{x,0.1 , 25}, PlotRange -> {{0.1,25},{10^-7,2}},Frame->True,PlotStyle->{Thin,Dotted}]

Now, here is some experimental data, regularly sampled .

data = {{1.2764388088113436`, 
    0.9918433685990196`}, {14.040826896924779`, 
    1.039932674224706`}, {26.805214985038212`, 
    0.7668281260594487`}, {39.56960307315165`, 
    0.5541859444708012`}, {52.33399116126508`, 
    0.40558676506099095`}, {65.09837924937852`, 
    0.30200232836386576`}, {77.86276733749196`, 
    0.2286803518200177`}, {90.6271554256054`, 
    0.17581993710977767`}, {103.39154351371883`, 
    0.13702931614982772`}, {116.15593160183226`, 
    0.10809719547183608`}, {128.9203196899457`, 
    0.0861995799489013`}, {141.68470777805913`, 
    0.06940652880001477`}, {154.44909586617257`, 
    0.056374722695911164`}, {167.213483954286`, 
    0.04615306910946258`}, {179.97787204239944`, 
    0.03805754908451407`}, {192.74226013051288`, 
    0.031589130420006925`}, {205.5066482186263`, 
    0.026378950612791056`}, {218.27103630673975`, 
    0.022151084939091497`}, {231.03542439485318`, 
    0.018696856482112126`}, {243.79981248296662`, 
    0.015856849289144947`}, {256.56420057108005`, 
    0.013508143629118478`}, {269.3285886591935`, 
    0.011555143338079379`}, {282.0929767473069`, 
    0.009922907703155834`}, {294.85736483542036`, 
    0.008552251717773794`}, {307.6217529235338`, 
    0.007396109628381036`}, {320.3861410116472`, 
    0.006416810850135384`}, {333.15052909976066`, 
    0.005584021550679567`}, {345.9149171878741`, 
    0.004873176551416507`}, {358.67930527598753`, 
    0.004264275619711748`}, {371.44369336410097`, 
    0.0037409528409629005`}, {384.2080814522144`, 
    0.0032897522559864737`}, {396.97246954032784`, 
    0.002899560454562362`}, {409.73685762844127`, 
    0.002561159440875691`}, {422.5012457165547`, 
    0.002266872270914283`}, {435.26563380466814`, 
    0.0020102806981750123`}, {448.0300218927816`, 
    0.0017859990432204295`}, {460.794409980895`, 
    0.0015894922101397037`}, {473.55879806900845`, 
    0.001416928552876123`}, {486.3231861571219`, 
    0.0012650603925953878`}, {499.0875742452353`, 
    0.0011311265809514637`}, {511.85196233334875`, 
    0.0010127727218457124`}, {524.6163504214622`, 
    0.0009079856000884424`}, {537.3807385095756`, 
    0.0008150390884601866`}, {550.145126597689`, 
    0.0007324493663087305`}, {562.9095146858025`, 
    0.0006589377212352913`}, {575.673902773916`, 
    0.000593399549291098`}, {588.4382908620294`, 
    0.0005348784400515834`}, {601.2026789501427`, 
    0.00048254444736299946`}, {613.9670670382562`, 
    0.00043567581697183264`}, {626.7314551263697`, 
    0.00039364357823440214`}, {639.4958432144831`, 
    0.00035589851604184386`}, {652.2602313025965`, 
    0.00032196012669276217`}, {665.02461939071`, 
    0.0002914072321374789`}, {677.7890074788235`, 
    0.0002638699842663306`}, {690.5533955669368`, 
    0.00023902303743189799`}, {703.3177836550502`, 
    0.00021657970531614398`}, {716.0821717431637`, 
    0.00019628694926365737`}, {728.8465598312772`, 
    0.0001779210706381663`}, {741.6109479193906`, 
    0.00016128400068432687`}, {754.375336007504`, 
    0.00014620009863953721`}, {767.1397240956175`, 
    0.00013251338312130742`}, {779.904112183731`, 
    0.00012008513366116102`}, {792.6685002718443`, 
    0.00010879180910665689`}, {805.4328883599577`, 
    0.00009852323782573207`}, {818.1972764480712`, 
    0.00008918104151080834`}, {830.9616645361847`, 
    0.0000806772601296132`}, {843.7260526242981`, 
    0.00007293315039685202`}, {856.4904407124114`, 
    0.00006587813420309541`}, {869.2548288005249`, 
    0.000059448876862823234`}, {882.0192168886384`, 
    0.000053588477938579856`}, {894.7836049767518`, 
    0.000048245759849728056`}, {907.5479930648652`, 
    0.00004337464155447283`}, {920.3123811529787`, 
    0.00003893358636232371`}, {933.0767692410922`, 
    0.00003488511444052035`}, {945.8411573292055`, 
    0.00003119537186341075`}, {958.6055454173189`, 
    0.000027833749152678517`}, {971.3699335054324`, 
    0.00002477254319742247`}, {984.1343215935459`, 
    0.00002198665725040371`}, {996.8987096816593`, 
    0.000019453334390497383`}, {1009.6630977697727`, 
    0.000017151920438466086`}, {1022.4274858578862`, 
    0.000015063652827881276`}, {1035.1918739459995`, 
    0.000013171472377419142`}, {1047.956262034113`, 
    0.000011459855295047797`}, {1060.7206501222263`, 
    9.914663077401455`*^-6}, {1073.4850382103398`, 
    8.523008256244883`*^-6}, {1086.2494262984533`, 
    7.273134194597726`*^-6}, {1099.0138143865665`, 
    6.154307353064888`*^-6}, {1111.77820247468`, 
    5.156720636776862`*^-6}, {1124.5425905627935`, 
    4.27140659888836`*^-6}, {1137.306978650907`, 
    3.4901594211369107`*^-6}, {1150.0713667390205`, 
    2.8054647183498464`*^-6}, {1162.8357548271338`, 
    2.2104363244156315`*^-6}, {1175.6001429152473`, 
    1.6987593142003669`*^-6}, {1188.3645310033608`, 
    1.264638600973566`*^-6}, {1201.128919091474`, 
    9.027525236606137`*^-7}, {1213.8933071795875`, 
    6.082109039808523`*^-7}, {1226.657695267701`, 
    3.765171114260987`*^-7}, {1239.4220833558145`, 
    2.0353372506191004`*^-7}, {1252.186471443928`, 
    8.54514261744926`*^-8}, {1264.9508595320412`, 
    1.8760795563738883`*^-8}};

It is possible to "fit" by eye (! ) the data, by trial and error using Manipulate, adjusting [Psi]0, g, but to do this , it is necessary to divide the data’s "timebase" by a constant x0, here x0= 65.

ndata=Thread[{data[[All,1]]/65,data[[All,2]]}];
Show[gr1, 
 ListPlot[ndata, ScalingFunctions -> {"Log", "Log"}, Frame -> True, 
  PlotStyle -> {Red, PointSize[0.01]}]]

I would like to fit the data using NonlinearModelFit (or FindFit), and by this way, find the best fit for [Psi]0,g and r0.
But it doesn’t work at all : the main problem comes from the limited domain of the interpolated functions dens, in general in the range {0,40} , the data being in the range {0,1500}, so that i don’t succeed at all to introduce properly the factor x0.
Dropping some datas helps a little, but this is not good, and I get imaginary values !!( reason why i tried to use Chop….)

nlm = NonlinearModelFit[Drop[Drop[data, 7], -5], 
  Chop[dens[[Psi][Psi]0, gg0, x /x0]], {{[Psi][Psi]0, 6.4}, {gg0, 
    2.3}, {x0, 65}}, x]

Here is an example of warning : InterpolatingFunction::dmval: Input value {14.2281} lies outside the range of data in the interpolating function. Extrapolation will be used.

Any idea ??

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP