Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11861

Re: NonlinearModelFit and assumptions on fit parameters

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: NonlinearModelFit and assumptions on fit parameters
Date 2012-09-24 04:41 +0000
Message-ID <k3oo9d$bav$1@smc.vnet.net> (permalink)
References <20120923070133.C4792686E@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


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@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.
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: NonlinearModelFit and assumptions on fit parameters Bob Hanlon <hanlonr357@gmail.com> - 2012-09-24 04:41 +0000

csiph-web