In[]:=
(*==================================================================*)(*LOGISTICvsSUBSTRATE-INHIBITIONFIT*)(*–noexternalpackages*)(*==================================================================*)ClearAll["Global`*"];​​​​(*------------------experimentaldata--------------------------*)​​tData={0,60,120,180,240,300,360,420,480};​​yData={0.,0.10,0.25,0.40,0.55,0.66,0.73,0.78,0.80};​​σ=0.05*Max[yData];(*5%errorbar*)​​tmax=Last[tData];​​​​(*------------------ODEright–handsides-----------------------*)​​logIF[P1_?NumericQ,Cmax_?NumericQ,n_:3]:=NDSolveValue[{c'[t]==P1*(1-(c[t]/Cmax)^n),c[0]==0},c,{t,0,tmax},Method->"StiffnessSwitching",MaxStepFraction->0.05];​​​​inhIF[P1_?NumericQ,KI_?NumericQ]:=NDSolveValue[{c'[t]==P1*KI/(KI+c[t]),c[0]==0},c,{t,0,tmax},Method->"StiffnessSwitching",MaxStepFraction->0.05];​​​​χ2Log[{P1_,Cmax_}]:=With[{f=logIF[P1,Cmax]},If[Head[f]===InterpolatingFunction,Total[((yData-f/@tData)/σ)^2],10^6]];(*penaltyonfailure*)​​​​χ2Inh[{P1_,KI_}]:=With[{f=inhIF[P1,KI]},If[Head[f]===InterpolatingFunction,Total[((yData-f/@tData)/σ)^2],10^6]];​​​​(*------------------logisticfit-------------------------------*)​​resLog=NMinimize[{χ2Log[{P1,Cmax}],0.0001<P1<0.2&&(*boxconstraints*)0.5<Cmax<2},{{P1,0.02},{Cmax,1}},Method->"NelderMead"];​​{χ2BestL,rulesL}=resLog;​​​​(*------------------inhibitionfit-----------------------------*)​​resInh=NMinimize[{χ2Inh[{P1,KI}],0.0001<P1<0.2&&0.01<KI<5},{{P1,0.02},{KI,0.3}},Method->"NelderMead"];​​{χ2BestI,rulesI}=resInh;​​​​(*------------------report-------------------------------------*)​​Print["Logistic best-fit : ",P1/.rulesL//NumberForm[#,4]&," (P1) ",Cmax/.rulesL//NumberForm[#,4]&," (Cmax) χ² = ",NumberForm[χ2BestL,4]];​​Print["Inhibition best-fit: ",P1/.rulesI//NumberForm[#,4]&," (P1) ",KI/.rulesI//NumberForm[#,4]&," (KI) χ² = ",NumberForm[χ2BestI,4]];​​​​(*------------------curves&plot------------------------------*)​​curveLog=logIF[P1/.rulesL,Cmax/.rulesL]/@tData;​​curveInh=inhIF[P1/.rulesI,KI/.rulesI]/@tData;​​​​ListPlot[{Transpose[{tData,yData}],(*reddata*)Transpose[{tData,curveLog}],(*blacklogistic*)Transpose[{tData,curveInh}](*blueinhibition*)},PlotStyle->{Red,Black,Blue},PlotLegends->{"exp","logistic","inhibition"},Frame->True,FrameLabel->{"time (min)","suc (mM)"},ImageSize->400]​​
NMinimize
:Variables {{P1,0.02},{Cmax,1}} should be a list of variables, with each element being a variable, or a list containing a variable and lower and upper bounds for the starting region for that variable.
Set
:Lists {χ2BestL,rulesL} and NMinimize[{1000000,0.0001<P1<0.2&&0.5<Cmax<2},{{P1,0.02},{Cmax,1}},MethodNelderMead] are not the same shape.
NMinimize
:Variables {{P1,0.02},{KI,0.3}} should be a list of variables, with each element being a variable, or a list containing a variable and lower and upper bounds for the starting region for that variable.
Set
:Lists {χ2BestI,rulesI} and NMinimize[{1000000,0.0001<P1<0.2&&0.01<KI<5},{{P1,0.02},{KI,0.3}},MethodNelderMead] are not the same shape.
ReplaceAll
:{rulesL} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
ReplaceAll
:{rulesL} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
Logistic best-fit : P1/.rulesL (P1) Cmax/.rulesL (Cmax) χ² = χ2BestL
ReplaceAll
:{rulesI} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
ReplaceAll
:{rulesI} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
Inhibition best-fit: P1/.rulesI (P1) KI/.rulesI (KI) χ² = χ2BestI
ReplaceAll
:{rulesL} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
ReplaceAll
:{rulesL} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
ReplaceAll
:{rulesI} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
ReplaceAll
:{rulesI} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.
Out[]=
exp
logistic
inhibition