Skip to main content

differential equations - Fitting experimental data by using ParametricNDSolveValue and NonlinearModelFit


I am a newcomer to Mathematica. Basically I just want to fit the data (enzyme kinetic data) shown below to a system of odes' by using NonlinearModelFit. The data, an 101x2 array, contains time in the first column and substrate concentration in the second. The model contains 4 species (e[t], es[t], s[t] and p[t]) and species s[t] is the one I want to fit the data to. I get the following error:



"The function value {<<1>>} is not a list of real numbers with dimensions {101} at {k1,k2,k3} = {4.,3.,1.`}". >>



Clicking on ">>" sends me to the basic NonlinearModelFit help page and I'm stuck there. The entire code is shown below. Thanks if anybody can help.


Francesco


(*some data*)
data={{0, 4.9112}, {20., 4.75011}, {40., 4.43818}, {60., 4.28744}, {80.,

3.97296}, {100., 3.86888}, {120., 3.69122}, {140., 3.59596}, {160.,
3.22247}, {180., 2.85438}, {200., 2.81939}, {220., 2.88236}, {240.,
2.49125}, {260., 2.55379}, {280., 2.33662}, {300., 2.34136}, {320.,
1.88169}, {340., 1.9444}, {360., 1.73578}, {380., 2.04545}, {400.,
1.74068}, {420., 1.70471}, {440., 1.37455}, {460., 1.35169}, {480.,
1.29391}, {500., 1.35778}, {520., 1.1509}, {540., 1.18335}, {560.,
0.846087}, {580., 0.957338}, {600., 0.855021}, {620.,
0.727364}, {640., 0.886429}, {660., 0.817111}, {680.,
0.748117}, {700., 0.569694}, {720., 0.77641}, {740.,
0.661459}, {760., 0.561378}, {780., 0.56037}, {800.,

0.500522}, {820., 0.322087}, {840., 0.44058}, {860.,
0.359604}, {880., 0.31989}, {900., 0.278633}, {920.,
0.318697}, {940., 0.150813}, {960., 0.427698}, {980.,
0.364589}, {1000., 0.292937}, {1020., 0.27481}, {1040.,
0.182754}, {1060., 0.349605}, {1080., 0.220416}, {1100.,
0.149073}, {1120., 0.343196}, {1140., 0.173815}, {1160.,
0.126286}, {1180., 0.145337}, {1200., 0.0800335}, {1220.,
0.043485}, {1240., 0.399296}, {1260., 0.303941}, {1280.,
0.161308}, {1300., -0.00255049}, {1320., 0.0296389}, {1340.,
0.0919508}, {1360.,

0.182537}, {1380., -0.0356638}, {1400., -0.140977}, {1420.,
-0.0581143}, {1440., 0.115227}, {1460., 0.116371}, {1480.,
0.118025}, {1500., 0.0556984}, {1520., 0.0831993}, {1540.,
0.0135393}, {1560., 0.143889}, {1580., -0.0817538}, {1600.,
0.0968327}, {1620., -0.0364522}, {1640., 0.0121839}, {1660.,
0.0983604}, {1680., 0.144547}, {1700., -0.0734307}, {1720.,
0.162225}, {1740., 0.100122}, {1760., 0.0253859}, {1780.,
0.0108251}, {1800., 0.00686486}, {1820., -0.00330938}, {1840.,
0.0277739}, {1860., 0.0291533}, {1880., 0.105267}, {1900.,
0.174073}, {1920., 0.0668537}, {1940., -0.00195318}, {1960.,

0.080458}, {1980., 0.0352437}, {2000., -0.0870161}};
(* Dimensions[data] {101, 2} *)

tmax = Max[data[[All, 1]]];

(* the model, k1, k2, k3 are the parameters *)

model = ParametricNDSolveValue[{e'[t] == (k2 + k3) es[t]
- k1 e[t] s[t], es'[t] == -e'[t], s'[t] == k2 es[t] - k1 e[t] s[t],
p'[t] == k3 es[t], e[0] == 0.001, s[0] == 5, es[0] == 0,

p[0] == 0}, s[t], {t, 0, tmax}, {k1, k2, k3}]

fit = NonlinearModelFit[data,model[k1, k2, k3][t], {{k1, 4.}, {k2, 3}, {k3, 1}}, t];
plotfit = Plot[model[k1, k2, k3] /. fit, {t, 0, tmax}];
plotdata = ListPlot[data, PlotStyle -> PointSize[0.02]];
Show[plotfit, plotdata]


Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...