Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: maximization with array of constraints

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128393] [mg128393] Re: maximization with array of constraints
  • From: Dana DeLouis <dana01 at me.com>
  • Date: Fri, 12 Oct 2012 00:01:07 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

> . . . my data is an array with two columns and 100 rows, I would have 100 constraints. . .

Hi.  Just some fun food for thought.  ;>)

Your 2-variable linear constraints makes it a little special.
If your data was all positive, you could reduce the workload of NMaximize to only 1 constraint.
Assume your data was all positive, and the following list represented 100 rows.

data = {{5,5},{5,6},{4,20}};

your 100 constraints would look like this:

const = Thread[data.{x,y}>0]

{5 x+5 y>0,5 x+6 y>0,4 x+20 y>0}

Do a region plot of the above.

RegionPlot[const,{x,-4,4},{y,-4,4},GridLines->Automatic]

You would have a hundred lines, but as you can see, if x is positive also, there is only 1 line that needs to be considered.  It's the one with the smallest absolute slope.


Clear[a,x,b,y];
Reduce[a x+b y>0&&b>0,y,Reals]
b>0&& y >  -((a x)/b)

So, y must be the largest of   -a/b
(largest of the negative values)

-data[[All,1]] / data[[All,-1]] 

{-1,-(5/6),-(1/5)}

{Min[%],Max[%]}
{-1,-(1/5)}

So, the largest of the numbers is =E2=88=921/5, so the last equation above is the only constraint one must add.

4 x+20 y>0

If your data had -x values, then you would just have to add the Min value above for an additional constraint.
(See chart as to why it changes)

5 x+5 y>0


If you wanted to carry it further, and y had negative values, you would just add 2 more constraints.

Reduce[a x+b y >0 && b<0,y,Reals]
b<0 && y < -((a x)/b)


= = = = = = = = = =
HTH   :>)
=E2=80=A8Dana DeLouis
=E2=80=A8= = = = = = = = = =



On Thursday, September 27, 2012 2:14:09 AM UTC-5, Felipe wrote:
> Hi,
>
>
>
>       I am trying to maximize a function using NMaximize and I have a large list of constraints that I would like to write with a loop or as an array.
>
>
>
> It looks like the following:
>
>
>
> NMaximize[{myfunction[x,y] ,  x*mydata[[1,row,1]] + y*mydata[[1,row,2]] >0 }]
>
>
>
> and I want the restriction to be valid for the numbers in each row of the "mydata" array. That is, if mydata is an array with two columns and 100 rows, I would have 100 constraints, which are too many to enter manually. 
>
> Can I write a loop for the constraints inside NMaximize ? Do you have some suggestion on how to write this? I was not able to find it in earlier posts.
>
>
>
> Thank you very much for your help
>
> Felipe





  • Prev by Date: Re: D under Sum
  • Next by Date: Re: trouble with obtaining eigenvalue of parametric matrix
  • Previous by thread: Re: maximization with array of constraints
  • Next by thread: Re: How create new style sheet- Mathematica 8