MathGroup Archive 2008

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91872] Re: How I can fit data with a parametric equation?
  • From: dinodeblasio at gmail.com
  • Date: Thu, 11 Sep 2008 06:14:30 -0400 (EDT)
  • References: <ga5ld2$rrc$1@smc.vnet.net> <ga82ut$ri1$1@smc.vnet.net>

On 10 Set, 12:10, Szabolcs Horv=E1t <szhor... at gmail.com> wrote:
> dinodebla... at gmail.com wrote:
> > Hello everybody,
> > I have a list of  {x,y} data and from a theoretical calculation I kno=
w
> > that the data should be fitted by an equation, for example:
>
> > y=ax+bx+c; where a, b, c are constant parameters.
>
> > The question is how i can find the best fit for my data finding the
> > value of this parameters.
>
> > Do mathematica has a specific function for that?
>
> Try searching the documentation for "fitting" ... the first result, Fit,
> does exactly what you describe here.

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"

(1 - k x) (1 - (k x)/q) (1 - (k p x)/q)

{xx, yy} = data\[Transpose]

{{1, 28, 54, 81, 117, 260}, {1, 0.719188, 0.357465, 0.182114,
0.166082,
  0.132766}}

Try1

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]

{k -> 0.00586032, p -> 2.86841, q ->
2.86841}                             "here we have the parameters
fitting the curve"

expr1 = express /. f1

(1 - 0.00586032 x) (1 - 0.00586032 x) (1 - 0.00204306 x)

yyfit = expr1 /. x -> xx

{0.986295, 0.658775, 0.415684, 0.230288, 0.0751917, 0.128567}

yy - yyfit

{0.0137055, 0.0604133, -0.0582186, -0.0481737, 0.0908904, 0.00419858}

Norm[%]

0.133516

Norm[yy - ((express /. f1) /. x -> xx)]

0.133516

f11 = {k, p, q} /.
   Table[FindFit[
     data, (1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q), {{k, k0}, {p, 1.5},
{q, 1}},
     x, MaxIterations -> 200], {k0, 0.01, 1, 0.1}] // TableForm


f11 = Table[
  FindFit[data, (1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q), {{k, k0}, {p,
1.5}, {q,              "here i am trying with k from 0.01 to 1"
     1}}, x, MaxIterations -> 200], {k0, 0.01, 1, 0.1}]



Norm[yy - ((express /. #) /. x -> xx)] & /@ f11

{0.133516, 0.133516, 0.133516, 0.133516, 0.162362, 0.133516, 0.162362,
\
0.133516, 0.133516, 0.133516}

% // Min

0.133516
"Here i find the minimum for Norm and find the position
at
which i have the best value of the fitting"

Position[%%, %]

{{4}, {6}, {8}}

% // Union

{0.133516, 0.133516, 0.133516, 0.133516, 0.162362}


  • Prev by Date: Re: How to simplify ArcCos[x/Sqrt[x^2+y^2]] to Pi/2-ArcTan[x/Abs[y]]?
  • Next by Date: Zoomable ListPlot
  • Previous by thread: Re: How I can fit data with a parametric equation?
  • Next by thread: Re: How I can fit data with a parametric equation?