Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11861 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2012-09-24 04:41 +0000 |
| Last post | 2012-09-24 04:41 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: NonlinearModelFit and assumptions on fit parameters Bob Hanlon <hanlonr357@gmail.com> - 2012-09-24 04:41 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2012-09-24 04:41 +0000 |
| Subject | Re: NonlinearModelFit and assumptions on fit parameters |
| Message-ID | <k3oo9d$bav$1@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@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 top | Article view | comp.soft-sys.math.mathematica
csiph-web