Re: Re: Problem with element and Maximize

• To: mathgroup at smc.vnet.net
• Subject: [mg83015] Re: [mg82814] Re: [mg82746] Problem with element and Maximize
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Wed, 7 Nov 2007 06:36:04 -0500 (EST)
• References: <219557.50206.qm@web26010.mail.ukl.yahoo.com>

```That's not the polynomial I got from Rationalize; if you got a different
one from the same input, you must have a different version of Mathematica
or a different OS, different chip, etc. I had already noticed that if I
used Chop@Rationalize[eq,0], then Maximize failed -- too-large integers
involved, I assume -- so I suggest you use a larger tolerance, such as:

data = {{0, 0}, {10, 10}, {20, 0}, {30, 10}};
eq = Fit[data, {1, x, x^2, x^3}, x]
proxy = Rationalize[eq, 10^-6]
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

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

{273/25, {x -> 7}}

10.92

That's obviously an easier problem than

proxy = Rationalize[eq, 10^-15]
Maximize[{proxy, x \[Element] Integers, x <= 20}, x]
eq /. Last@%

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

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

10.92

or

proxy = Rationalize[eq, 0]
Maximize[{proxy, x \[Element] Integers, x <= 20}, x]
eq /. Last@%

4/2039489352675603 + (10 x)/3 - (
245650888765664 x^2)/818836295885547 + (
14612439855600 x^3)/2191865978340001

Maximize[{4/2039489352675603 + (10 x)/3 - (245650888765664 x^2)/
818836295885547 + (14612439855600 x^3)/2191865978340001,
x \[Element] Integers, x <= 20}, x]

ReplaceAll::reps: {x} is neither a list of replacement rules nor a \
valid dispatch table, and so cannot be used for replacing. >>

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

Bobby

On Mon, 05 Nov 2007 09:46:11 -0600, Peter van Summeren
<peter_van_summeren at yahoo.co.uk> wrote:

> Hello Bobby,
> the solution you gave does not work for me(see code below).
> Maximize does not give a solution.
> Maximize[{1/379250494936462 + (105718301111983 x)/31715490333595 - (
>    3 x^2)/10 + x^3/150, x \[Element] Integers, x <= 20}, x]
> And this is what Mathematica gives.
> ReplaceAll::reps: {x} is neither a list of replacement rules nor a \
> valid dispatch table, and so cannot be used for replacing. >>
>
>  I do not know enough of Mathematica to see what went wrong.
> Could you give me some idea?
> with friendly greetings,
> Peter van Summeren
>
> ----- Original Message ----
> From: DrMajorBob <drmajorbob at bigfoot.com>
> To: mathgroup at smc.vnet.net
> Sent: Wednesday, 31 October, 2007 12:20:56 PM
> Subject: [mg82814] Re: [mg82746] Problem with element and Maximize
>
> 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: Reproducing a hash code
• Next by Date: Re: Can you get a package back to a notebook easily?
• Previous by thread: Re: Re: Problem with element and Maximize
• Next by thread: Re: Simplifying polynomial and rounding problems