# Manipulating the value of the rules

I have a fitted model given in the code below and I am trying to shift the function to get its maxima in the center ($t=0$). The variable center[i] controls the center position of the basis function and therefore I want to shift all the centers of these basis functions (here I have used 2 basis functions).

NBasisFun = 2;
model = Sum[a[i] Exp[-(b[i])^2 (t - center[i])^2], {i, 1, NBasisFun, 1}];
fitPrams = {a[1] -> 6.13531, a[2] -> 0.501507, b[1] -> 4.97662, b[2] -> 1.82646,
center[1] -> -0.127246, center[2] -> -0.393956};

Plot[model /. fitPrams, {t, -1, 1}]


To shift all the basis functions, I find the maxima of the fitted function and the corresponding $t$ value (PeakLocation) using NMaximize then I create a new model i.e. PeakShiftedModel where I add this value to center[i].

PeakLocation = t /. Last[NMaximize[model /. fitPrams, t]]
PeakShiftedModel = Sum[a[i] Exp[-(b[i])^2 (t - center[i] + PeakLocation)^2],
{i, 1, NBasisFun, 1}] /. fitPrams

Plot[PeakShiftedModel, {t, -1, 1}]


While this approach works, I want to change directly the fitted parameters by adding the PeakLocation to the center positions (center[i]) of the fitted parameters fitPrams. Something that looks like this:

fitPrams = {a[1] -> 6.13531, a[2] -> 0.501507, b[1] -> 4.97662, b[2] -> 1.82646,
center[1] -> -0.127246 - PeakLocation, center[2] -> -0.393956 - PeakLocation};


How do I do it?

• Try fitPrams /. (center[k_] -> val_) :> (center[k] -> val - PeakLocation). – J. M. will be back soon Mar 14 '18 at 11:53
• yes, that seems to work good. – dykes Mar 14 '18 at 11:58

fitPrams[[-2 ;;, -1]] = fitPrams[[-2 ;;, -1]] - PeakLocation;