       Re: Problem with element and Maximize

• To: mathgroup at smc.vnet.net
• Subject: [mg82814] Re: [mg82746] Problem with element and Maximize
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Wed, 31 Oct 2007 06:20:56 -0500 (EST)
• References: <4209462.1193744482571.JavaMail.root@m35>

```Don't round the real-valued solution; it won't always get you the best
integer solution.

But this should work:

data = {{0, 0}, {10, 10}, {20, 0}, {30, 10}};
eq = Fit[data, {1, x, x^2, x^3}, x]
proxy = Rationalize[eq, 10^-15]
Maximize[{proxy, x \[Element] Integers, x <= 20}, x]
eq /. Last@%

1.96128*10^-15 + 3.33333 x - 0.3 x^2 + 0.00666667 x^3

1/509872338168900 + (10 x)/3 - (3 x^2)/10 + x^3/150

{5567805932804389/509872338168900, {x -> 7}}

10.92

Without the upper bound the function has no maximum and, with approximate
coefficients, Maximize can't use efficient integer optimization methods.

Bobby

On Tue, 30 Oct 2007 03:31:51 -0500, Uncle Paul <paul at desinc.com> wrote:

> I'm not sure what I am doing wrong.  I am trying to get the nearest
> integer maximim for the mentioned equation.  I could round the X
> value, but I would like to operate Mathematica correctly.
>
> (*generate the equation*)
> data = {{0, 0}, {10, 10}, {20, 0}, {30, 10}};
> eq = Fit[data, {1, x, x^2, x^3}, x]
> Plot[eq, {x, 0, 30}]
>
> Maximize[{eq, x \[Element] Integers}, x]  (*wrong!*)
>
> Maximize[{eq}, x]      (*correct, but not integer, of course*)
>
>
> Best Regards,
> Paul
>
>

--

DrMajorBob at bigfoot.com

```

• Prev by Date: Re: Setting Negatives to Zero
• Next by Date: Re: "Accumulate" in Mathematica 6
• Previous by thread: Re: Problem with element and Maximize
• Next by thread: library.wolfram submissions