0

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.

P Pyne
  • 453
  • 2
  • 9
  • 1
    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? – Henrik Schumacher Jun 02 '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]). – Henrik Schumacher Jun 02 '18 at 13:20
  • 1
    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. – John Doty Jun 02 '18 at 13:43
  • 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]]])}], hExp[ -(0.693)( Log[1 + 2a*([Nu] - n)/d]/a )^2] , {a, d, n, h}, t], {t, 0, 2}] – P Pyne Jun 02 '18 at 13:44
  • I have a data having function like y[[i]]=f[x[[i]],t]. I want to find the fitted parameters for a fixed value of t. then changing t I can get the another fitted parameters. I need all the fitted parameters with t to plot a time dependent slope. – P Pyne Jun 02 '18 at 13:51
  • 2

1 Answers1

1

maybe something like this:

SeedRandom[1]
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

kglr
  • 394,356
  • 18
  • 477
  • 896