MathGroup Archive 2011

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

Search the Archive

Re: NonlinearModelFit: Freezing parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117531] Re: NonlinearModelFit: Freezing parameters
  • From: Peter <petsie at dordos.net>
  • Date: Tue, 22 Mar 2011 05:05:35 -0500 (EST)
  • References: <im201l$tl$1@smc.vnet.net> <im4iru$d29$1@smc.vnet.net> <im7c2v$3f$1@smc.vnet.net>

Am 21.03.2011 12:16, schrieb dg:
> On Mar 20, 2:54 am, Peter Pein<pet... at dordos.net>  wrote:
>
>>
>> Hi,
>>
>> you can wrap a Block[] around the call to NonlinearModelFit (NMF). You
>> just have to change the way how the parameters are given to NMF using
>> Variables:
>>
>> In[1]:= model=a0+a1 x+a2 x^2;
>> data=Table[{x,.25+x^(3/2)},{x,0,2,1/3}];
>>
>> the normal call to NMF:
>> In[3]:= f0=NonlinearModelFit[data,model,Variables[{a0,a1,a2}],x]//Normal
>> Out[3]= 0.22546 + 0.601959 x + 0.416822 x^2
>>
>> Say you knew a0=1/4:
>>
>> In[4]:= f1=Block[{a0=.25},
>> NonlinearModelFit[data,model,Variables[{a0,a1,a2}],x]//Normal
>> ]
>> Out[4]= 0.25 + 0.557096 x + 0.434077 x^2
>>
>> hth,
>> Peter
>
> Peter,
> that's a neat trick. I think this does not work with models that are
> not polynomials. For example, model= c0*Sin[c1*x].
>


I take the variables from the set of the parameters, not from the model:

In[1]:= params = {c0, c1};
vars = {x};
model = c0*Sin[c1*x];
data = Table[{x, Sin[E*x]}, {x, -1, 2, 1/4}];

In[5]:= Normal[NonlinearModelFit[data, model, Variables[params], vars]]

Out[5]= 0.9999999999999987*Sin[2.7182818284590176*x]

In[6]:= Block[{c1 = 5/2},
          Normal[NonlinearModelFit[data, model, Variables[params], vars]]
         ]

Out[6]= 0.9641129280282692*Sin[(5*x)/2]

Peter


  • Prev by Date: Re: Chop in Mathematica 8.0.1
  • Next by Date: Re: NestList integration bug?
  • Previous by thread: Re: NonlinearModelFit: Freezing parameters
  • Next by thread: Mathematica 8 bug (related to Graph[])