       Re: How I can fit data with a parametric equation?

• To: mathgroup at smc.vnet.net
• Subject: [mg91908] Re: How I can fit data with a parametric equation?
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Fri, 12 Sep 2008 05:29:02 -0400 (EDT)

```On 9/11/08 at 6:14 AM, dinodeblasio at gmail.com wrote:

>Hello and thanks for your collaboration, I read a little bit and I
>wrote the following code: "when I try to do the FindFit command, the
>parameters have to be positive, so i was searching for the optimal
>values of the parameter that fit the data. How I can modify my code
>in order to find the best parameters fitting the data?I tried to do
>the Norm between the value of the data and the value of the equation
>but i cant do more. Thanks.

>Remove["Global`*"] 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) "this is the
>equation with which i want to fit the data"

When you want to place constraints on the parameters, using
NMinimize is probably going to work for you better than FindFit.

First create a function that computes the summed square error

In:= ss[x_, y_, k_, p_, q_] :=
Total[((1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q) - y)^2]

Here I've separated the x,y components to simplify the code

In:= {xx, yy} = Transpose[data];

Now, NMinimize can be used to find the desired parameters

In:= NMinimize[{ss[xx, yy, k, p, q], k > 0 && p > 0 && q >
0}, {k,
p, q}]

Out= {0.0178264,{k->0.00204306,p->1.,q->0.348625}}

In:= Show[
ListPlot[data, PlotRange -> All, Frame -> True, Axes -> None,
PlotMarkers -> Automatic], Plot[express /. Last[%20], {x, 0, 300}]]

Shows the estimates give a reasonable fit to the data.

```

• Prev by Date: Re: Alternating sums of large numbers
• Next by Date: Re: Text-based interface: Editing line input
• Previous by thread: Re: How I can fit data with a parametric equation?