MathGroup Archive 2012

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

Search the Archive

Re: NonlinearModelFit and assumptions on fit parameters


As shown in the documentation

data = {{1, 1}, {2, 2}, {3, 3.2}};

fitFuncExactNoLosses[a_, b_, x_] =
  a*x^2 + b + x;

(nlm1 = NonlinearModelFit[data,
    {fitFuncExactNoLosses[a, b, x], b > 0},
    {{a, 1}, {b, 1}}, x]) // Normal

7.890764227861177*^-7 + x +
   0.018364206486339258*x^2

nlm1["FitResiduals"]

{-0.018365, -0.0734576, 0.0347214}

(nlm2 = NonlinearModelFit[data,
    {fitFuncExactNoLosses[a, b, x], b > 0},
    {a, b}, x]) // Normal

0.011226160044776182 + x +
   0.016760582112590634*x^2

nlm2["FitResiduals"]

{-0.0279867, -0.0782685, 0.0379286}

Plot[{nlm1[x], nlm2[x]}, {x, 0, 4},
 Epilog -> {Red,
   AbsolutePointSize[4],
   Point[data]}]


Bob Hanlon


On Sun, Sep 23, 2012 at 3:01 AM, Niles <niels.martinsen at gmail.com> wrote:
> Hi
>
> I have a set of data (x, y) that I can succesfully fit a nonlinear function to using NonlinearModelFit:
>
>
> data = {{1, 1}, {2, 2}, {3, 3.2}};
> fitFuncExactNoLosses[a_, b_, x_] := a*x^2 + b + x;
> nlm = NonlinearModelFit[data, fitFuncExactNoLosses[a, b, x],
>   {
>    {a, 1},
>    {b, 1}},
>   x]
>
>
> However, the paramter "b" comes out negative and it *must* be positive. Is there a way to utilize assumptions such that b is constrained to be grater than zero?
>
> Best,
> Niels.
>



  • Prev by Date: regression MIMO problem, fix the parameters
  • Next by Date: Re: NonlinearModelFit and assumptions on fit parameters
  • Previous by thread: NonlinearModelFit and assumptions on fit parameters
  • Next by thread: Re: NonlinearModelFit and assumptions on fit parameters