How to fit a data set in an iterative way?

I am going to fit a data set in the following way. I have a data set $y$ vs. $x$. $y$ is again a function of $t$ i.e. $y=f(t)$. With varying $t$, I can get different $y$ and can plot $y$ vs. $x$, and fit each plot to find the fitting parameters. I need all the fitting parameters with varying $t$. I have used code like this:

dataf = Table[FindFit[data, a + b*i, {a, b}, i], {i, 1, 5}]

• Hi Partha. It's not entirely clear to me what you are trying to achieve there. Could you please provide an example data set for data? Do you mean that your model looks like y[[i]] = f(x[[i]],t) with lists x and y prescribed and t being a further parameter? Jun 2 '18 at 13:08
• Err... sorry for using incorrect syntax. I meant $y_i = f(x_i,t)$ (or y[[i]] == f[x[[i]], t]). Jun 2 '18 at 13:20
• You have i serving two different roles here. You're telling FindFit that it's the independent variable in the fitting formula, but then you're trying to use it as a Table index, too. I can't understand what you're attempting. Jun 2 '18 at 13:43
• My entire equation looks like: fit = Table[ FindFit[Transpose[{[Nu], (NormalisedIntensity/ avglifetime)*([Tau][]*Exp[-t/[Tau][]] + [Tau][]* Exp[-t/[Tau][]] + [Tau][]*Exp[-t/[Tau][]])}], h*Exp[ -(0.693)*( Log[1 + 2*a*([Nu] - n)/d]/a )^2] , {a, d, n, h}, t], {t, 0, 2}] Jun 2 '18 at 13:44
• – kglr
Jun 2 '18 at 14:19

maybe something like this:

SeedRandom
data = {#, #^2 RandomReal[{.9, 1.1}]} & /@ Range;
f[x_, t_] := a + b x^t;

fitf[t_] := FindFit[data, f[x, t], {a, b}, x]
fittedmodels = Table[With[{t = t}, Evaluate[f[x, t] /. fitf[t]]], {t, 1, 5}];
Show[Plot[Evaluate@fittedmodels, {x, 0, 100}, PlotStyle -> Thick,
PlotLegends -> ("t = " <> ToString[#] & /@ Range)],
ListPlot[data, PlotStyle -> PointSize[Medium]]] 