Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Problem with Maximize and conditions.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51059] Re: Problem with Maximize and conditions.
  • From: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>
  • Date: Sun, 3 Oct 2004 05:47:27 -0400 (EDT)
  • References: <cjlna7$q7f$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

If you break it down into steps you can solve this one;

Start by reducing the conditions the solution must satisfy.

a=Reduce[{ 1/20 x+y+5z\[Equal]100, x \[Element] Integers,
      y \[Element] Integers, z\[Element]Integers, 
0<x<99,0<y<99,0<z<99},{x,y,
      z}]

which gives

x == 20 && y == 4 && z == 19 || x == 20 && y == 9 && z == 18 ||
x == 20 && y == 14 && z == 17 || x == 20 && y == 19 && z == 16 ||
x == 20 && y == 24 && z == 15 || x == 20 && y == 29 && z == 14 ||
x == 20 && y == 34 && z == 13 || x == 20 && y == 39 && z == 12 ||
x == 20 && y == 44 && z == 11 || x == 20 && y == 49 && z == 10 ||
x == 20 && y == 54 && z == 9 || x == 20 && y == 59 && z == 8 ||
x == 20 && y == 64 && z == 7 || x == 20 && y == 69 && z == 6 ||
x == 20 && y == 74 && z == 5 || x == 20 && y == 79 && z == 4 ||
x == 20 && y == 84 && z == 3 || x == 20 && y == 89 && z == 2 ||
x == 20 && y == 94 && z == 1 || x == 40 && y == 3 && z == 19 ||
x == 40 && y == 8 && z == 18 || x == 40 && y == 13 && z == 17 ||
x == 40 && y == 18 && z == 16 || x == 40 && y == 23 && z == 15 ||
x == 40 && y == 28 && z == 14 || x == 40 && y == 33 && z == 13 ||
x == 40 && y == 38 && z == 12 || x == 40 && y == 43 && z == 11 ||
x == 40 && y == 48 && z == 10 || x == 40 && y == 53 && z == 9 ||
x == 40 && y == 58 && z == 8 || x == 40 && y == 63 && z == 7 ||
x == 40 && y == 68 && z == 6 || x == 40 && y == 73 && z == 5 ||
x == 40 && y == 78 && z == 4 || x == 40 && y == 83 && z == 3 ||
x == 40 && y == 88 && z == 2 || x == 40 && y == 93 && z == 1 ||
x == 60 && y == 2 && z == 19 || x == 60 && y == 7 && z == 18 ||
x == 60 && y == 12 && z == 17 || x == 60 && y == 17 && z == 16 ||
x == 60 && y == 22 && z == 15 || x == 60 && y == 27 && z == 14 ||
x == 60 && y == 32 && z == 13 || x == 60 && y == 37 && z == 12 ||
x == 60 && y == 42 && z == 11 || x == 60 && y == 47 && z == 10 ||
x == 60 && y == 52 && z == 9 || x == 60 && y == 57 && z == 8 ||
x == 60 && y == 62 && z == 7 || x == 60 && y == 67 && z == 6 ||
x == 60 && y == 72 && z == 5 || x == 60 && y == 77 && z == 4 ||
x == 60 && y == 82 && z == 3 || x == 60 && y == 87 && z == 2 ||
x == 60 && y == 92 && z == 1 || x == 80 && y == 1 && z == 19 ||
x == 80 && y == 6 && z == 18 || x == 80 && y == 11 && z == 17 ||
x == 80 && y == 16 && z == 16 || x == 80 && y == 21 && z == 15 ||
x == 80 && y == 26 && z == 14 || x == 80 && y == 31 && z == 13 ||
x == 80 && y == 36 && z == 12 || x == 80 && y == 41 && z == 11 ||
x == 80 && y == 46 && z == 10 || x == 80 && y == 51 && z == 9 ||
x == 80 && y == 56 && z == 8 || x == 80 && y == 61 && z == 7 ||
x == 80 && y == 66 && z == 6 || x == 80 && y == 71 && z == 5 ||
x == 80 && y == 76 && z == 4 || x == 80 && y == 81 && z == 3 ||
x == 80 && y == 86 && z == 2 || x == 80 && y == 91 && z == 1

Convert the logical expression produced above to a set of rules.

b={ToRules[a]}

which gives

{{x -> 20, y -> 4, z -> 19}, {x -> 20, y -> 9, z -> 18}, {x -> 20, y -> 14,
z -> 17}, {x -> 20, y -> 19, z -> 16}, {x -> 20, y -> 24,
z -> 15}, {x -> 20, y -> 29, z -> 14}, {x -> 20, y -> 34,
z -> 13}, {x -> 20, y -> 39, z -> 12}, {x -> 20, y -> 44,
z -> 11}, {x -> 20, y -> 49, z -> 10}, {x -> 20, y -> 54,
z -> 9}, {x -> 20, y -> 59, z -> 8}, {x -> 20, y -> 64, z -> 7}, {x -> 20,
y -> 69, z -> 6}, {x -> 20, y -> 74, z -> 5}, {x -> 20, y -> 79,
z -> 4}, {x -> 20, y -> 84, z -> 3}, {x -> 20, y -> 89, z -> 2}, {x -> 20,
y -> 94, z -> 1}, {x -> 40, y -> 3, z -> 19}, {x -> 40, y -> 8,
z -> 18}, {x -> 40, y -> 13, z -> 17}, {x -> 40, y -> 18,
z -> 16}, {x -> 40, y -> 23, z -> 15}, {x -> 40, y -> 28,
z -> 14}, {x -> 40, y -> 33, z -> 13}, {x -> 40, y -> 38,
z -> 12}, {x -> 40, y -> 43, z -> 11}, {x -> 40, y -> 48,
z -> 10}, {x -> 40, y -> 53, z -> 9}, {x -> 40, y -> 58,
z -> 8}, {x -> 40, y -> 63, z -> 7}, {x -> 40, y -> 68, z -> 6}, {x -> 40,
y -> 73, z -> 5}, {x -> 40, y -> 78, z -> 4}, {x -> 40, y -> 83,
z -> 3}, {x -> 40, y -> 88, z -> 2}, {x -> 40, y -> 93, z -> 1}, {x -> 60,
y -> 2, z -> 19}, {x -> 60, y -> 7, z -> 18}, {x -> 60, y -> 12,
z -> 17}, {x -> 60, y -> 17, z -> 16}, {x -> 60, y -> 22,
z -> 15}, {x -> 60, y -> 27, z -> 14}, {x -> 60, y -> 32,
z -> 13}, {x -> 60, y -> 37, z -> 12}, {x -> 60, y -> 42,
z -> 11}, {x -> 60, y -> 47, z -> 10}, {x -> 60, y -> 52,
z -> 9}, {x -> 60, y -> 57, z -> 8}, {x -> 60, y -> 62, z -> 7}, {x -> 60,
y -> 67, z -> 6}, {x -> 60, y -> 72, z -> 5}, {x -> 60, y -> 77,
z -> 4}, {x -> 60, y -> 82, z -> 3}, {x -> 60, y -> 87, z -> 2}, {x -> 60,
y -> 92, z -> 1}, {x -> 80, y -> 1, z -> 19}, {x -> 80, y -> 6,
z -> 18}, {x -> 80, y -> 11, z -> 17}, {x -> 80, y -> 16,
z -> 16}, {x -> 80, y -> 21, z -> 15}, {x -> 80, y -> 26,
z -> 14}, {x -> 80, y -> 31, z -> 13}, {x -> 80, y -> 36,
z -> 12}, {x -> 80, y -> 41, z -> 11}, {x -> 80, y -> 46,
z -> 10}, {x -> 80, y -> 51, z -> 9}, {x -> 80, y -> 56,
z -> 8}, {x -> 80, y -> 61, z -> 7}, {x -> 80, y -> 66, z -> 6}, {x -> 80,
y -> 71, z -> 5}, {x -> 80, y -> 76, z -> 4}, {x -> 80, y -> 81,
z -> 3}, {x -> 80, y -> 86, z -> 2}, {x -> 80, y -> 91, z -> 1}}

Evaluate your expression for each of the possible solutions.

c=x+y+z/.b

which gives

{43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, 99, 103, 107, 111, 
\
115, 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 102, 106, 110, 114, 118, 122, \
126, 130, 134, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, \
133, 137, 141, 145, 149, 153, 100, 104, 108, 112, 116, 120, 124, 128, 132, \
136, 140, 144, 148, 152, 156, 160, 164, 168, 172}

Locate the solution that minimises your expression.

Position[c,Min[c]]

which gives

{1}

Display the minimum solution.

b\[LeftDoubleBracket]1\[RightDoubleBracket]

which gives

{x\[Rule]20,y\[Rule]4,z\[Rule]19}

Steve Luttrell

"Nacho" <ncc1701zzz at hotmail.com> wrote in message 
news:cjlna7$q7f$1 at smc.vnet.net...
> Hello.
>
> I was trying to solve a problem with Mathematica 5 and I am getting
> strange results.
>
> The problem is:
>
> Minimize x+y+z, with the condition that 1/20x+y+5z==100 and x,y,z are
> Integers between 1 and 98 (inclusive).
>
> So I use:
>
> Minimize[{x+y+z, 1/20 x+y+5z\[Equal]100,  x \[Element] Integers,
>    y \[Element] Integers, z\[Element]Integers, 0<x<99,0<y<99,0<z<99},
> {x,y,
>    z}]
>
> I have copied the text using "Plain text" option, I hope it's fine.
>
> This returns the same expression, I suppose that Mathematica cannot
> resolve it. So I use NMinimize:
>
> NMinimize[{x+y+z, 1/20 x+y+5z\[Equal]100,  x \[Element] Integers,
>    y \[Element] Integers, z\[Element]Integers, 0<x<99,0<y<99,0<z<99},
> {x,y,
>    z}]
>
> Now I get a result, but rather weird...
>
> \!\({25.`, {x -> 1, y -> 5, z -> 1899\/100}}\)
>
> The minimum of x+y+z is 25 but z is 1899/100
> 1899/100 is not a Integers, and the nearest Integer, 19, doesn't
> satisfy 1/20x+y+5z==100, and also x+y+z is not 25 but 24.99
>
> I don't know why Mathematica has returned a Real when I specified an
> Integers. I suppose that it is related to the use of NMinimize. I
> suppose that it considers that 18.99 is so near of 19 that it can be
> considered an Integer.
>
> If you remove the condition of z being an Integer, the result changes,
> so it is affecting. Also, if you ask for "1899/100 e Integers" it
> returns False.
>
> So, does anybody know how to solve this? Ideally, I would like to know
> why Minimize doesn't work (so I have to use NMinimize), but in any
> case, how to solve the problem.
>
> Thanks!
> 



  • Prev by Date: Re: Problem with Maximize and conditions.
  • Next by Date: Re: Problem with Maximize and conditions.
  • Previous by thread: Re: Problem with Maximize and conditions.
  • Next by thread: Re: Problem with Maximize and conditions.