(1) There really is no reason to attach a notebook. The code is short enough that it can go directly into a post.
(2) There is no evidence of any debugging effort whatever. The NDSolve result, for example, will not evaluate as utilized inside FindFit
.
(3) There is only one independent variable, and it is t
. As there are three simultaneous fits needed, we emulate that with a discrete variable n
that takes on values 1,2,3. For this to work we need to rearrange the date list a bit.
Cinetica2 = {{0, 0.04`, 16.04`, 0.3`}, {2, 0.19`, 13.52`, 0.51`}, {4, 0.39`, 10.99`, 1.22`}, {6, 1.11`, 8.23`, 2.96`},
{8, 1.96`, 0.37`, 6.08`}, {10, 2.09`, 0.31`, 5.82`}, {12, 2.41`, 0.28`, 5.69`}, {14, 2.41`, 0.26`, 5.62`}};
Rearrange the data:
clists = Flatten[Map[Thread[{First[#], Range[3], Rest[#]}] &, Cinetica2], 1]
(* Out[165]= {{0, 1, 0.04}, {0, 2, 16.04}, {0, 3, 0.3}, {2, 1, 0.19}, {2,
2, 13.52}, {2, 3, 0.51}, {4, 1, 0.39}, {4, 2, 10.99}, {4, 3,
1.22}, {6, 1, 1.11}, {6, 2, 8.23}, {6, 3, 2.96}, {8, 1, 1.96}, {8,
2, 0.37}, {8, 3, 6.08}, {10, 1, 2.09}, {10, 2, 0.31}, {10, 3,
5.82}, {12, 1, 2.41}, {12, 2, 0.28}, {12, 3, 5.69}, {14, 1,
2.41}, {14, 2, 0.26}, {14, 3, 5.62}} *)
Redo the function in such a way that it will actually evaluate. One can and should test that it evaluates to a number, when fed appropriate input.
Clear[LoteGModel];
LoteGModel[Ke_?NumberQ, YxsG_?NumberQ, ms_?NumberQ,
YpsG_?NumberQ, \[Alpha]a_?NumberQ, \[Beta]b_?NumberQ] :=
LoteGModel[Ke, YxsG, ms, YpsG, \[Alpha]a, \[Beta]b] =
NDSolveValue[{{Y'[t] == (\[Mu]ma S[t]/(Ke + S[t]))*Log[Kx/Y[t]]*
Y[t], Y[0] == 0.04},
{S'[t] == -(((\[Mu]ma S[t]/(Ke + S[t]))*Log[Kx/Y[t]]*Y[t])/
YxsG) - ms Y[
t] - (\[Alpha]a*((\[Mu]ma S[t]/(Ke + S[t]))*Log[Kx/Y[t]]*
Y[t]) + \[Beta]b*Y[t])/YpsG,
S[0] == 15 }, {Et'[
t] == \[Alpha]a*( (\[Mu]ma S[t]/(Ke + S[t]))*Log[Kx/Y[t]]*
Y[t]) + \[Beta]b*Y[t], Et[0] == 0.3}},
{Y, S, Et}, {t, 15}]
Clear[func]
func[Ke_?NumberQ, YxsG_?NumberQ, ms_?NumberQ,
YpsG_?NumberQ, \[Alpha]a_?NumberQ, \[Beta]b_?NumberQ, t_?NumberQ,
n_?NumberQ] :=
LoteGModel[Ke, YxsG, ms, YpsG, \[Alpha]a, \[Beta]b][[n]][t]
Now run the fit. Warnings indicate there may be trouble.
fitGomp =
FindFit[clists,
func[Ke, YxsG, ms, YpsG, \[Alpha]a, \[Beta]b, t,
n], {{Ke, 0.025}, {YxsG, 0.44}, {ms, 0.036}, {YpsG,
0.48}, {\[Alpha]a, 0.9}, {\[Beta]b, 0.08}}, {t, n}]
During evaluation of In[175]:= NDSolveValue::ndsz: At t == 7.1147359866114295`, step size is effectively zero; singularity or stiff system suspected. >>
During evaluation of In[175]:= InterpolatingFunction::dmval: Input value {8.} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
During evaluation of In[175]:= InterpolatingFunction::dmval: Input value {8.} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
During evaluation of In[175]:= InterpolatingFunction::dmval: Input value {8.} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
During evaluation of In[175]:= General::stop: Further output of InterpolatingFunction::dmval will be suppressed during this calculation. >>
During evaluation of In[175]:= NDSolveValue::ndsz: At t == 9.45455859284449`, step size is effectively zero; singularity or stiff system suspected. >>
During evaluation of In[175]:= NDSolveValue::ndsz: At t == 9.558957684515919`, step size is effectively zero; singularity or stiff system suspected. >>
During evaluation of In[175]:= General::stop: Further output of NDSolveValue::ndsz will be suppressed during this calculation. >>
During evaluation of In[175]:= FindFit::sszero: The step size in the search has become less than the tolerance prescribed by the PrecisionGoal option, but the gradient is larger than the tolerance specified by the AccuracyGoal option. There is a possibility that the method has stalled at a point that is not a local minimum. >>
(* Out[175]= {Ke -> 8.046436990185919*10^-7, YxsG -> 0.4891746182309673,
ms -> 0.1809314600576526,
YpsG -> 0.5974714908245637, \[Alpha]a ->
2.426821441437095, \[Beta]b -> 0.08677711620145376} *)
One can assess that this is at least a plausible result by comparing explicit evaluations at the fitted parameter values with clists
.
func2 = func[Ke, YxsG, ms, YpsG, \[Alpha]a, \[Beta]b, t, n] /. fitGomp;
Flatten[Table[{t, n, func2}, {t, 0, 14, 2}, {n, 1, 3}], 1]
(* Out[186]= {{0, 1, 0.04}, {0, 2, 15.}, {0, 3, 0.3}, {2, 1,
0.2770802783180547}, {2, 2, 13.46442074844808}, {2, 3,
0.898749873186528}, {4, 1, 0.768809615766145}, {4, 2,
10.13049265182656}, {4, 3, 2.180254427838512}, {6, 1,
1.316805932379483}, {6, 2, 6.101006017102625}, {6, 3,
3.691954237495139}, {8, 1, 1.748846456442421}, {8, 2,
2.454657792902989}, {8, 3, 5.008687899807296}, {10, 1,
1.948546275680985}, {10, 2, -3.578836840383028*10^-7}, {10, 3,
5.82196503324831}, {12, 1, 1.751107445453094}, {12,
2, -2.785847756390413*10^-7}, {12, 3, 5.663556487512911}, {14, 1,
1.573674295875138}, {14, 2, -2.280475064379094*10^-7}, {14, 3,
5.52119884657305}} *)
Here is a measure of relative errors, that is, discrepancies between data and fitted model.
Map[{Most[#[[1]]],
Abs[Last[#[[1]]] - Last[#[[2]]]]/
Sqrt[Last[#[[1]]]^2 + Last[#[[2]]]^2]} &,
Transpose[{clists, evals}]]
(* Out[189]= {{{0, 1}, 0.}, {{0, 2}, 0.0473568702539026}, {{0, 3},
0.}, {{2, 1}, 0.2591933469342784}, {{2, 2},
0.002912820154303103}, {{2, 3}, 0.3761965972571338}, {{4, 1},
0.439417580307384}, {{4, 2}, 0.05750441950496325}, {{4, 3},
0.3843506227871235}, {{6, 1}, 0.120080287441452}, {{6, 2},
0.2078129017888882}, {{6, 3}, 0.1546807481166434}, {{8, 1},
0.0803844078497986}, {{8, 2}, 0.8397795549170736}, {{8, 3},
0.1359982682960941}, {{10, 1}, 0.04950374839530081}, {{10, 2},
1.00000115446283}, {{10, 3}, 0.0002387033995335336}, {{12, 1},
0.2211786530788786}, {{12, 2}, 1.000000994945133}, {{12, 3},
0.003293828907684501}, {{14, 1}, 0.2905634359494454}, {{14, 2},
1.000000877105409}, {{14, 3}, 0.01254087995090153}} *)