Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extracting Parameter Values from NonlinearModelFit

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127916] Re: Extracting Parameter Values from NonlinearModelFit
  • From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
  • Date: Sat, 1 Sep 2012 02:26:46 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

Hi,

I'm modelling a series (>2000) of data points (5x2 lists) using NonlinearModelFit, and trying to extract the Fitted Parameter Values to separate lists using the following code:

model = a Exp[-k x];
i = 1;
For[i = 1, i <= Length[data],
  {nlm = NonlinearModelFit[data[[i]], {model, k<1}, {a, b}, x]["BestFitParameters"];
   aValues = Append[aValues, nlm[[1, 2]]];
   kValues = Append[kValues, nlm[[2, 2]]]},
  i++
  ];

I'm able to determine the Parameters via nlm, but can't extract the parameter values.

Any thoughts?

Thanks in advance!

C

Hi,
The problem comes from the fact that in the model you use parameter k, and in the fitting operator - parameter b. The second source of an inconvenience (not really a problem) is the use of the loop, which is generally not recommended in Mathematica. Your aim can be achieved in a more easy way. For example, like follows.

Here I construct something like the data points to be fitted (to have something to play with). The points are contained in the list entitled tab2:

tab1 = Transpose@{RandomReal[{0, 1}, {5}], RandomReal[{-1, 0}, {5}]};
tab2 = Table[{x,
    tab1[[i, 1]]*Exp[tab1[[i, 2]]*x] + RandomReal[{-0.01, 0.01}]}, {i,
     1, 5}, {x, 0, 1, 0.1}];

For example its first sublist is:

tab2[[1]]

{{0., 0.639913}, {0.1, 0.614459}, {0.2, 0.588334}, {0.3,
  0.569105}, {0.4, 0.54342}, {0.5, 0.516209}, {0.6, 0.504349}, {0.7,
  0.490187}, {0.8, 0.459}, {0.9, 0.446124}, {1., 0.421486}}

And there are 5 such different sublists.

This is the list tab3 containing solutions for the parameters a and b of your model:

model = a Exp[-b x];
tab3 = Table[
  FindFit[tab2[[i]], model, {a, b}, x], {i, 1, 5}]

{{a -> 0.568633, b -> 0.364295}, {a -> 0.433001,
  b -> 0.319931}, {a -> 0.286261, b -> 0.397863}, {a -> 0.88219,
  b -> 0.0503344}, {a -> 0.80377, b -> 0.843876}}

If you execute this, you will visualize the fitting:

Table[Show[{ListPlot[tab2[[i]], PlotStyle -> Red],
   Plot[model /. tab3[[i]], {x, 0, 1}]}], {i, 1, 5}]

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu







  • Next by Date: Manipulate Export $Aborted
  • Next by thread: Manipulate Export $Aborted