Mathematica 9 is now available
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: [mg51119] Re: Problem with Maximize and conditions.
  • From: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>
  • Date: Tue, 5 Oct 2004 04:37:05 -0400 (EDT)
  • References: <cjlna7$q7f$1@smc.vnet.net> <cjoiig$alt$1@smc.vnet.net> <cjr9ea$ost$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Fred Simons' approach (another response to your original posting)

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}//Reduce},
{x,y,z}]

slickly achieves in one step what I clumsily did in several steps. It seems 
that the conditions you feed to Minimize are "improved" by being wrapped in 
Reduce.

However, sometimes it is a good idea to break the whole problem down into 
several steps just to keep a watchful eye on what Mathematica is getting up 
to. When you have all that working you can then combine the steps together.

Steve Luttrell

"Nacho" <ncc1701zzz at hotmail.com> wrote in message 
news:cjr9ea$ost$1 at smc.vnet.net...
> Hello Steve.
>
> Thanks for your answer. I like it, simple and effective! I didn't
> think in splitting the problem in parts... I was trying to solve it in
> just a step. I'm rather new to Mathematica.
>
> A good procedure for other kind of problems.
>
> Thanks.
>
>
> "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk> wrote in 
> message news:<cjoiig$alt$1 at smc.vnet.net>...
>> 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
> 



  • Prev by Date: Newbie facing $RecursionLimit and Stack Space on OSX
  • Next by Date: Re: Re: Problem with Maximize and conditions.
  • Previous by thread: Re: Problem with Maximize and conditions.
  • Next by thread: Re: Re: Problem with Maximize and conditions.