0
$\begingroup$

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[0] == 2, z[0] == 1, w[0] == 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][[3]][t]}, {t, 1, 10, 1}] + 
 Table[{0, RandomReal[{-20, 150}]}, {i, 1, 10, 1}]
 ListPlot[expwvals]
 nlf = NonlinearModelFit[expwvals,model[p1, p2, p3][[3]][t], {{p1, 1}, {p2, 
 3}, {p3, 5}}, t]

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

$\endgroup$
  • $\begingroup$ 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". $\endgroup$ – JimB Jun 14 '18 at 14:10
  • $\begingroup$ 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[1][y][t] == 2, p2 y[t] + Derivative[1][z][t] == 0, p3 y[t] z[t] + Derivative[1][w][t] == 1}, {y[0] == 2, z[0] == 1, w[0] == 1}}, {y, z, w}, {t, 0, 10}][t][[ 3]], {{p1, 1}, {p2, 3}, {p3, 5}}, t] meaning that selection [[3]] takes the third term of the model function {t,0,10} $\endgroup$ – Nitra Jun 14 '18 at 14:14
  • $\begingroup$ This isn't a complete fix but you'll need to use model[p1, p2, p3][[3]][t] rather than model[p1, p2, p3][t][[3]] in NonlinearModelFit. $\endgroup$ – JimB Jun 14 '18 at 15:04
  • $\begingroup$ @JimB This neither work JimB $\endgroup$ – Nitra Jun 14 '18 at 15:18
  • $\begingroup$ As I said it isn't a complete fix but model[1,3,5][[3]][5] produces a numerical value while model[1,3,5][5][[3]] does not. $\endgroup$ – JimB Jun 14 '18 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.