# NonlinearRegression with interpolation functions

I want something like this here

http://forums.wolfram.com/mathgroup/archive/2004/Oct/msg00031.html

But my model function uses interpolation functions (FROM NDSolve). How is that going?

CombiledData =
Join[Insert[#, 1, 2] & /@ dat1, Insert[#, 2, 2] & /@ dat2];

CombinedModel :=
Which[MDL == 1, Evaluate[First[g1 /. sol1[1, 0.3, 0.1]]], MDL == 2,
Evaluate[First[g2 /. sol1[1, 0.3, 0.2]]], True, 0];

regreport =
NonlinearRegress[CombiledData, CombinedModel, {t, MDL}, {gamma, c},
RegressionReport -> {BestFit, BestFitParameters}]


But this yields

NonlinearRegress[{{{-5., 0.999994}, 1, {-4.9, 0.999996}, {-4.8, 0.999997}, {-4.7, 0.999997}, {-4.6, 0.999997}, {-4.5, 0.999997}, {-4.4, 0.999997}, {-4.3, 0.999995}, {-4.2, 0.999995}, {-4.1, 0.999993}, {-4., 0.999992}, {-3.9, 0.999989}, {-3.8, 0.999986}, {-3.7, 0.999981}, {-3.6, 0.999974}, {-3.5, 0.999964}, {-3.4, 0.999952}, {-3.3, 0.999936}, {-3.2, 0.999913}, {-3.1, 0.999883}, {-3., 0.999842}, {-2.9, 0.999788}, {-2.8, 0.999713}, {-2.7, 0.999613}, {-2.6, 0.999478}, {-2.5, 0.999296}, {-2.4, 0.99905}, {-2.3, 0.998719}, {-2.2, 0.998272}, {-2.1, 0.99767}, {-2., 0.996859}, {-1.9, 0.995768}, {-1.8, 0.9943}, {-1.7, 0.99233}, {-1.6, 0.98969}, {-1.5, 0.986161}, {-1.4, 0.98146}, {-1.3, 0.975223}, {-1.2, 0.966999}, {-1.1, 0.956235}, {-1., 0.942283}, {-0.9, 0.924424}, {-0.8, 0.901918}, {-0.7, 0.874093}, {-0.6, 0.840472}, {-0.5, 0.80091}, {-0.4, 0.755714}, {-0.3, 0.705697}, {-0.2, 0.652123}, {-0.1, 0.596553}, {0., 0.54063}}, {{-5., 0.999994}, 2, {-4.9, 0.999996}, {-4.8, 0.999997}, {-4.7, 0.999997}, {-4.6, 0.999997}, {-4.5, 0.999997}, {-4.4, 0.999997}, {-4.3, 0.999995}, {-4.2, 0.999995}, {-4.1, 0.999993}, {-4., 0.999992}, {-3.9, 0.999989}, {-3.8, 0.999986}, {-3.7, 0.999981}, {-3.6, 0.999974}, {-3.5, 0.999964}, {-3.4, 0.999952}, {-3.3, 0.999936}, {-3.2, 0.999913}, {-3.1, 0.999883}, {-3., 0.999842}, {-2.9, 0.999788}, {-2.8, 0.999713}, {-2.7, 0.999613}, {-2.6, 0.999478}, {-2.5, 0.999296}, {-2.4, 0.99905}, {-2.3, 0.998719}, {-2.2, 0.998272}, {-2.1, 0.99767}, {-2., 0.996859}, {-1.9, 0.995768}, {-1.8, 0.9943}, {-1.7, 0.99233}, {-1.6, 0.98969}, {-1.5, 0.986162}, {-1.4, 0.98146}, {-1.3, 0.975225}, {-1.2, 0.967001}, {-1.1, 0.956239}, {-1., 0.94229}, {-0.9, 0.924437}, {-0.8, 0.90194}, {-0.7, 0.874131}, {-0.6, 0.840536}, {-0.5, 0.801014}, {-0.4, 0.755878}, {-0.3, 0.705949}, {-0.2, 0.652495}, {-0.1, 0.597084}, {0., 0.541361}}}, Which[MDL == 1, (1 + 0.01 c) (!(* TagBox[ RowBox[{"InterpolatingFunction", "[", RowBox[{ RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{"-", "10."}], ",", "50."}], "}"}], "}"}], ",", "\<\"<>\">"}], "]"}], False, Editable->False])[t]^2 + !(* TagBox[ RowBox[{"InterpolatingFunction", "[", RowBox[{ RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{"-", "10."}], ",", "50."}], "}"}], "}"}], ",", "\<\"<>\">"}], "]"}], False, Editable->False])[t]^2)^gamma, MDL == 2, (1 + 0.04 c) (!(* TagBox[ RowBox[{"InterpolatingFunction", "[", RowBox[{ RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{"-", "10."}], ",", "50."}], "}"}], "}"}], ",", "\<\"<>\">"}], "]"}], False, Editable->False])[t]^2 + !(* TagBox[ RowBox[{"InterpolatingFunction", "[", RowBox[{ RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{"-", "10."}], ",", "50."}], "}"}], "}"}], ",", "\<\"<>\">"}], "]"}], False, Editable->False])[t]^2)^gamma, True, 0], {t, MDL}, {gamma, c}, RegressionReport -> {BestFit, BestFitParameters}]

-
NonlinearRegress isn't a function defined in Mathematica - I think you want NonlinearModelFit –  bobthechemist Sep 29 at 14:13
@bobthechemist That depends on your version –  belisarius Sep 29 at 14:22
@belisarius My bad. My (Mathematica) life effectively started with v8. –  bobthechemist Sep 29 at 14:23
Thanks. Now it works. I get Which[MDL == 1, (1 + 0.01 0.00419029) ((\!(* TagBox[ RowBox[{"<<", "1", ">>"}], False, Editable->False]) <<1>> <<1>>])^2 + <<1>>^2)^0.552148, MDL == 2, <<1>>, True, 0] –  user2098925 Sep 29 at 14:24
The formatting is weird. but why it does not fit for model 2 like for model 1? –  user2098925 Sep 29 at 14:24