Re: How to find the best fit for a list {x,y} of data

• To: mathgroup at smc.vnet.net
• Subject: [mg91923] Re: How to find the best fit for a list {x,y} of data
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sat, 13 Sep 2008 05:53:21 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK

```dinodeblasio at gmail.com wrote:

> I have the list and the y=f(x) equation
>
> data = {{1, 1}, {28, 0.719188377}, {54, 0.35746493}, {81,
>     0.182114228}, {117, 0.166082164}, {260, 0.132765531}};
> express = (1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q)
>
> (1 - k x) (1 - (k x)/q) (1 - (k p x)/q)
>
>
> "k,q and p are parameters; then I do the fitting":
>
> f1 = FindFit[data, (1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q), {{k, 0.01},
> {p, 1.5}, {q,1}}, x, MaxIterations -> 200]
>
> "and I obtain":
>
> {k -> 0.00586032, p -> 2.86841, q -> 2.86841}
>
> "My question is: how I can find the best fit to my data for values of
> (k,q,p) >0" ??

Some tweaking and experimentation gives you a variety of options to get
excellent approximations.

In[1]:= data = {{1, 1}, {28, 0.719188377}, {54, 0.35746493}, {81,
0.182114228}, {117, 0.166082164}, {260, 0.132765531}};

expr = (1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q);

(* You could add the constrains k > 0 && p > 0 && q > 0 and set the
option Method to NMinimize *)

f1 = FindFit[data, {expr, k > 0 && p > 0 && q > 0}, {k, p, q}, x,
Method -> NMinimize]

Plot[expr /. f1, {x, 1, 260}, Epilog -> Point /@ data]

(* Or set the precision of the data to, say, 20 and test several methods

f1 = FindFit[SetPrecision[data, 20], expr, {k, p, q}, x,
Method -> #] & /@ {"ConjugateGradient", "LevenbergMarquardt",
"Newton", "QuasiNewton"}

Plot[expr /. #, {x, 1, 260}, Epilog -> Point /@ data] & /@ f1

Out[3]= {k -> 0.00586017, p -> 0.348616, q -> 0.999951}

Out[5]= {{k -> 0.0058603184189148254461, p -> 0.34862536795753106130,
q -> 1.0000000000759083932}, {k -> 0.0058603184186521820593,
p -> 0.34862536786743369247,
q -> 0.99999999999757125104}, {k -> 0.0020430556645278991563,
p -> 0.99999999999994081062,
q -> 0.34862536786785086450}, {k -> 0.0058603184186556336479,
p -> 0.34862536786744803858, q -> 0.99999999999859996068}}59996068}}

Regards,
-- Jean-Marc

```

• Prev by Date: Re: Alternating sums of large numbers
• Next by Date: Re: How can you get the list of all used variables and
• Previous by thread: How to find the best fit for a list {x,y} of data
• Next by thread: Re: How to find the best fit for a list {x,y} of data