# How to find best fit parameters from interpolation functions by using NDSolveValue

This is an example of what I want to do. I want to calculate the best fit parameters from a set of experimental data with 3 and more differential equations. I use NDSolveValue to find the interpolation functions and I select one of them to calculate the best fit parameters. As example :

model[par1_: 1, par2_: 0.1, par3_: 2] := Module[{},

rate1 = par1*y[t];
rate2 = par2*y[t];
rate3 = par3*y[t]*z[t];

eq1 = y'[t] + rate1 == 2;
eq2 = z'[t] + rate2 == 0;
eq3 = w'[t] + rate3 == 1;

eqs = {eq1, eq2, eq3};
ic = {y == 2, z == 1, w == 1};
NDSolveValue[{eqs, ic}, {y, z, w}, {t, 0, 10}]
]


Now I create some random data for the w and run the NonLinearModelFit function

 expwvals =
Table[Evaluate@{t, model[1, 3, 5][][t]}, {t, 1, 10, 1}] +
Table[{0, RandomReal[{-20, 150}]}, {i, 1, 10, 1}]
ListPlot[expwvals]
nlf = NonlinearModelFit[expwvals,model[p1, p2, p3][][t], {{p1, 1}, {p2,
3}, {p3, 5}}, t]


However the selection of the third interpolation function as, model[p1, p2, p3][][t] doesn't work. How could I select the w interpolation factor to use it for fitting ? Your help is appreciated.

• What do the warning messages tell you? You'll get better and quicker help if you give a more explicit description than "it doesn't work". – JimB Jun 14 '18 at 14:10
• it returns back lines of errors and finally NonlinearModelFit[{{1, 49.3192}, {2, 118.915}, {3, 300.731}, {4, 509.547}, {5, 686.623}, {6, 1069.96}, {7, 1468.58}, {8, 1855.46}, {9, 2400.71}, {10, 3050.91}}, NDSolveValue[{{p1 y[t] + Derivative[y][t] == 2, p2 y[t] + Derivative[z][t] == 0, p3 y[t] z[t] + Derivative[w][t] == 1}, {y == 2, z == 1, w == 1}}, {y, z, w}, {t, 0, 10}][t][[ 3]], {{p1, 1}, {p2, 3}, {p3, 5}}, t] meaning that selection [] takes the third term of the model function {t,0,10} – Nitra Jun 14 '18 at 14:14
• This isn't a complete fix but you'll need to use model[p1, p2, p3][][t] rather than model[p1, p2, p3][t][] in NonlinearModelFit. – JimB Jun 14 '18 at 15:04
• @JimB This neither work JimB – Nitra Jun 14 '18 at 15:18
• As I said it isn't a complete fix but model[1,3,5][] produces a numerical value while model[1,3,5][] does not. – JimB Jun 14 '18 at 15:28