MathGroup Archive 2012

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

Search the Archive

Re: Message using FindFit with LevenbergMarquardt Method

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125480] Re: Message using FindFit with LevenbergMarquardt Method
  • From: Darren Glosemeyer <darreng at wolfram.com>
  • Date: Thu, 15 Mar 2012 00:30:17 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201203140541.AAA25797@smc.vnet.net>

On 3/14/2012 12:41 AM, geraldine oliveux wrote:
> Hello,
>
> I'm a new user of Mathematica. I'm trying to fit data to a model in
> which I have one parameter. I try to determine this parameter by
> Levenberg-Marquardt Method.
> I wrote the following lines :
> data = {{0., 0.425}, {60.6, 0.224}, {91.2, 0.1314}, {119.4, 0.0716},
> {150., 0.040}, {181.8, 0.0241}}
> u = t*(a*sqrt[e0])/2
> x = Tanh[t*(a*sqrt[e0])/2]
> Etac = e0*(1 - x^2)
> fit = FindFit[data, Etac, a, t, Method ->  "LevenbergMarquardt"]
>
> But it gives me the following message :
> FindFit::nrlnum: "The function value {0.,-0.224+0.425\ (1. -1.\
> Tanh[Times[<<2>>]]^2),-0.1314+0.425\ (1. -1.\
> Tanh[Times[<<2>>]]^2),-0.0716+0.425\ (1. -1.\
> Tanh[Times[<<2>>]]^2),-0.04+0.425\ (1. -1.\
> Tanh[Times[<<2>>]]^2),-0.0241+0.425\ (1. -1.\ Tanh[Times[<<2>>]]^2)}\
> \n is not a list of real numbers with dimensions {6} at {a} = {1.}. "
>
> What does it mean ? I think there is something I don't do well, and
> that it concerns the data declaration.
> Thank you in advance for your help,
> Best regards,
> G=E9raldine
>

The message means that the model did not evaluate to a real number for 
at least one of the data points for a value of a that the algorithm 
tried. It the particular example sent, this happens at the starting 
value for a, which is 1 by default.

There are a couple problems I see in the code. First sqrt should be 
Sqrt. With that fix, we can see there is still a problem by substituting 
the initial value of a and the t values from the data:

In[1]:= data = {{0., 0.425}, {60.6, 0.224}, {91.2, 0.1314}, {119.4,
     0.0716}, {150., 0.040}, {181.8, 0.0241}};
u = t*(a*Sqrt[e0])/2;
x = Tanh[t*(a*Sqrt[e0])/2];
Etac = e0*(1 - x^2);

In[5]:= Etac /. {a -> 1} /. t -> data[[All, 1]]

Out[5]= {1. e0, e0 (1 - Tanh[30.3 Sqrt[e0]]^2),
  e0 (1 - Tanh[45.6 Sqrt[e0]]^2), e0 (1 - Tanh[59.7 Sqrt[e0]]^2),
  e0 (1 - Tanh[75. Sqrt[e0]]^2), e0 (1 - Tanh[90.9 Sqrt[e0]]^2)}


The parameter e0 does not have a numeric value, so either it will need 
to be estimated by FindFit as well:


In[6]:= fit =
  FindFit[data, Etac, {a, e0}, t, Method -> "LevenbergMarquardt"]

Out[6]= {a -> -1.92292*10^23, e0 -> 0.425}


Or a numeric value will need to be given for it:


In[7]:= fit =
  FindFit[data, Etac /. e0 -> 3, a, t, Method -> "LevenbergMarquardt"]

Out[7]= {a -> 0.21875}


Darren Glosemeyer
Wolfram Research



  • Prev by Date: Re: Engineering requests
  • Next by Date: Eigenvalues, eigenvectors, matrix ranks, determinants, and all that stuff
  • Previous by thread: Re: Message using FindFit with LevenbergMarquardt Method
  • Next by thread: Re: Message using FindFit with LevenbergMarquardt Method