Re: NonlinearModelFit and assumptions on fit parameters
- To: mathgroup at smc.vnet.net
- Subject: [mg128205] Re: NonlinearModelFit and assumptions on fit parameters
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Mon, 24 Sep 2012 00:32:29 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20120923070133.C4792686E@smc.vnet.net>
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. >
- References:
- NonlinearModelFit and assumptions on fit parameters
- From: Niles <niels.martinsen@gmail.com>
- NonlinearModelFit and assumptions on fit parameters