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}]

This does not work. I don't understand how to express it? Please help.

  • 1
    $\begingroup$ 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? $\endgroup$ Jun 2, 2018 at 13:08
  • $\begingroup$ Err... sorry for using incorrect syntax. I meant $y_i = f(x_i,t)$ (or y[[i]] == f[x[[i]], t]). $\endgroup$ Jun 2, 2018 at 13:20
  • 1
    $\begingroup$ 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. $\endgroup$
    – John Doty
    Jun 2, 2018 at 13:43
  • $\begingroup$ My entire equation looks like: fit = Table[ FindFit[Transpose[{[Nu], (NormalisedIntensity/ avglifetime)*([Tau][[1]]*Exp[-t/[Tau][[2]]] + [Tau][[3]]* Exp[-t/[Tau][[4]]] + [Tau][[5]]*Exp[-t/[Tau][[6]]])}], h*Exp[ -(0.693)*( Log[1 + 2*a*([Nu] - n)/d]/a )^2] , {a, d, n, h}, t], {t, 0, 2}] $\endgroup$
    – P Pyne
    Jun 2, 2018 at 13:44
  • 2
    $\begingroup$ this may be useful: Curve fitting by running through hundreds of models and return the one with best fit $\endgroup$
    – kglr
    Jun 2, 2018 at 14:19

1 Answer 1


maybe something like this:

data = {#, #^2 RandomReal[{.9, 1.1}]} & /@ Range[100];
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[5])], 
 ListPlot[data, PlotStyle -> PointSize[Medium]]]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.