Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: FindMinimum numerical constraint functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110868] Re: FindMinimum numerical constraint functions
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 8 Jul 2010 20:35:36 -0400 (EDT)

On 7/8/10 at 7:41 AM, Stuart.Nettleton at uts.edu.au (Stuart Nettleton)
wrote:

>Hi, I am experimenting with external numerical constraint functions
>in FindMinimum. Would anyone understand how the second FindMinimum
>might be made to work in the way of the first?

>FindMinimum[{Sin[x ] Sin[2 y], {x^2 + y^2 < 3, -x < 0, -y < 0}}, {x,
>y}]
>Clear[obj, con]; vars = {x, y}; lenvars = Length[vars];

>obj[vars1_]:= Module[{subst = Thread[Array[m, lenvars] -> vars1]},
>ReplaceAll[Sin[m[1]] Sin[m[2]], subst]]/; VectorQ[vars1, NumberQ];

>con[vars2_] := Module[{subst = Thread[Array[n, lenvars] -> vars2]},
>ReplaceAll[{n[1]^2 + n[2]^2, -n[1], -n[2]}, subst]
>]/; VectorQ[vars2, NumberQ];

>FindMinimum[{obj, Thread[con[vars] < {3, 0, 0}]}, vars]

You have made both functions con and obj needlessly complex.
Additionally, you are requiring con to work for an array of
numbers. So, you will not get a list of constraints when this
function gets evaluated.

First, obj can be simplified to:

obj[vars_]:=Times@@Sin[vars]

and con can be simplified to:

con[vars_] := Flatten@{Plus@@vars^2, -vars}

Since both of these are defined using SetDelayed a terminating
semicolon is not needed. And since they both localize the
supplied argument, it is not necessary to define them with
uniquely named arguments.

With these definitions, the FindMinimum problem can be done as follows:

In[95]:= FindMinimum[{obj[vars], Thread[con[vars] < {3, 0, 0}]}, vars]

Out[95]= {3.41113*10^-12,{x->0.00256066,y->1.33213*10^-9}}

and to verify this is the same answer as you would have gotten
by explicitly typing everything:

In[96]:= FindMinimum[{Sin[x] Sin[ y], {x^2 + y^2 < 3, -x < 0, -y <
     0}}, {x, y}]

Out[96]= {3.41113*10^-12,{x->0.00256066,y->1.33213*10^-9}}



  • Prev by Date: Re: plot colored ellipsoid
  • Next by Date: Re: First nonzero in list
  • Previous by thread: Re: FindMinimum numerical constraint functions
  • Next by thread: Re: FindMinimum numerical constraint functions