Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NonlinearModelFit ... please find me only integers

47 views
Skip to first unread message

Ktota

unread,
Jan 8, 2010, 4:15:35 AM1/8/10
to
Hi there,

how can i tell NonlinearModelFit that a parameter it is supposed to
optimize should be only an Integer?

thank you

Konstantin

Bill Rowe

unread,
Jan 10, 2010, 3:28:19 AM1/10/10
to
On 1/8/10 at 4:15 AM, nuk...@gmail.com (Ktota) wrote:

>how can i tell NonlinearModelFit that a parameter it is supposed to
>optimize should be only an Integer?

As far as I know, this cannot be done using NonlinearModelFit.
NonlinearModelFit seems to be designed to do non-linear
regression with the usual assumptions. This is an unconstrained
optimization problem. Once you impose a constraint on any
parameter, the problem becomes a constrained optimization
problem. See:

tutorial/UnconstrainedOptimizationOverview
tutorial/ConstrainedOptimizationOverview

=46indFit or NMimimize can be used to find the best fit parameters
with constraints. Look at the second entry in the online
documentation for FindFit for syntax details.


Bob Hanlon

unread,
Jan 10, 2010, 3:29:34 AM1/10/10
to

You can try using Round in your model

data = {{0, 1}, {1, 0}, {3, 2},
{5, 4}, {6, 4}, {7, 5}};

f[x_] = NonlinearModelFit[data,
Log[a + b x^2], {a, b}, x] // Normal

Log[1.4263297975161129*x^2 + 1.5063204891556876]

f2[x_] = NonlinearModelFit[data,
Log[a + Round[b] x^2], {a, b}, x] // Normal

Log[x^2 + 1.5806558441280811]

f3[x_] = NonlinearModelFit[data,
Log[Round[a] + b x^2], {a, b}, x] // Normal

Log[1.444296658409274*x^2 + 1]

f4[x_] = NonlinearModelFit[data,
Log[Round[a] + Round[b] x^2], {a, b}, x] //
Normal // Quiet

Log[x^2 + 1]

Plot[Evaluate[Tooltip[#[x], #] & /@
{f, f2, f3, f4}], {x, 0, 7},
Epilog -> {Red, AbsolutePointSize[4],
Point[data]},
Frame -> True,
Axes -> False,
PlotRange ->
{{-0.25, 7.25}, {-0.25, 5.25}},
ImageSize -> 600]


Bob Hanlon

---- Ktota <nuk...@gmail.com> wrote:

=============
Hi there,

how can i tell NonlinearModelFit that a parameter it is supposed to
optimize should be only an Integer?

thank you

Konstantin


0 new messages