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

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

list manipulation - Selecting multiple columns from a matrix?

Sample data: data = { {{2013, 1, 1}, 24.13, 167.67, 231.82}, {{2013, 1, 2}, 32.15, 170.92, 225.99}, {{2013, 1, 3}, 35.43, 172.68, 221.67}, {{2013, 1, 4}, 36.73, 173.05, 218.32}, {{2013, 1, 5}, 58.19, 165.96, 197.05}, {{2013, 1, 6}, 69.99, 163.50, 187.52}, {{2013, 1, 7}, 71.37, 154.21, 175.58}, {{2013, 1, 8}, 72.51, 149.66, 163.25}}; I want a DateListPlot with three graphs, so for a matrix formed by columns 1 and 2, one for columns 1 and 3, and 1 for columns 1 and 4. At the moment I'm using this code: data2 = Transpose[{data[[All, 1]], data[[All, 2]]}]; data3 = Transpose[{data[[All, 1]], data[[All, 3]]}]; data4 = Transpose[{data[[All, 1]], data[[All, 4]]}]; DateListPlot[{data2, data3, data4}, Joined -> True, Filling -> {3 -> {1}}] but I have a hunch that this can be done more efficiently. I don't like the Transpose s in particular. Any ideas? edit (for extra credit) What if I need to multiply the second column by 2, which in my solution is simp...

calculus and analysis - Integral of the Sinc product

Let us consider the following integral $$ B_n = \int_0^\infty \prod_{k=1,3,5,\dots}^n\frac{\sin (x/k)}{x/k}dx $$ By definition, Sinc[x] == Sin[x]/x , therefore B[n_?OddQ] := Integrate[Product[Sinc[x/k], {k, 1, n, 2}], {x, 0, Infinity}] B /@ Range[1, 13, 2] {Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2} OK, everything is fine. But... B[15] 467807924713440738696537864469 Pi/935615849440640907310521750000 What's going on? Answer As Eckhard wrote in comments B[n] is the n-th Borwein integral . (The letter B was not accidental :) ) This funny properties of Borwein integrals is related to the Fourier transform of Sinc function FourierTransform[Sinc[x], x, k] 1/2 Sqrt[Pi/2] (Sign[1 - k] + Sign[1 + k]) Plot[%, {k, -2, 2}, Filling -> 0] which is the box function. The result is $\pi/2$ while the sum $$ 1/3+1/5+\dots+1/n $$ B_n = \frac{\pi}{2} - \pi \bigg(\sum_{k=3,5,\ldots}^n\frac{1}{k} -1\biggr)^\frac{n-1}{2}\prod_{k=3,5,\dots}^n\frac{k}{k-1}. $$ For $n=15$ it is equal to $$ \frac{46780...