Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11897 > unrolled thread

Re: maximization with array of constraints

Started byDana DeLouis <dana01@me.com>
First post2012-09-28 03:09 +0000
Last post2012-10-11 08:40 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: maximization with array of constraints Dana DeLouis <dana01@me.com> - 2012-09-28 03:09 +0000
    Re: maximization with array of constraints felipe.benguria@gmail.com - 2012-10-11 06:15 +0000
    Re: maximization with array of constraints felipe.benguria@gmail.com - 2012-10-11 08:40 +0000

#11897 — Re: maximization with array of constraints

FromDana DeLouis <dana01@me.com>
Date2012-09-28 03:09 +0000
SubjectRe: maximization with array of constraints
Message-ID<k434cf$ne5$1@smc.vnet.net>
> .. if mydata is an array with two columns and 100 rows, I would have 100 constraints, which are too many to enter manually.  

> .. x*mydata[[1,row,1]] + y*mydata[[1,row,2]] >0

Hi.  If I understood your question correctly, here is one idea:
(* Make sure your MyFunction is not unbounded *)

mydata=RandomInteger[{1,9},{10,2}]

{{7,8},{9,4},{5,7},{4,3},{2,2},{2,7},{8,5},{9,1},{6,5},{5,7}}

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

{
7 x+8 y>0,
9 x+4 y>0,
5 x+7 y>0,
4 x+3 y>0,
2 x+2 y>0,
2 x+7 y>0,
8 x+5 y>0,
9 x+y>0,
6 x+5 y>0,
5 x+7 y>0
}

MyFunction[x_,y_]:=-3x^2-4y+3

NMaximize[{MyFunction[x,y],const}, {x,y} ]

{3.10884, {x->0.190508,y->-0.0544307} }

= = = = = = = = = =
HTH  :>)
Dana DeLouis
Mac & Mathematica 8
= = = = = = = = = =




On Thursday, September 27, 2012 3:14:09 AM UTC-4, 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


[toc] | [next] | [standalone]


#12038

Fromfelipe.benguria@gmail.com
Date2012-10-11 06:15 +0000
Message-ID<k55o5f$e82$1@smc.vnet.net>
In reply to#11897
Thank you very much everyone for your help. I am new to this forum and had thought I had answered thanking earlier, but my message had not gone through.
I believe all the suggestions above worked to solve my problem.

Thanks.








El jueves, 27 de septiembre de 2012 23:10:29 UTC-4, Dana DeLouis escribi
:
> > .. if mydata is an array with two columns and 100 rows, I would have 100 constraints, which are too many to enter manually. > .. x*mydata[[1,row,1]] + y*mydata[[1,row,2]] >0 Hi. If I understood your question correctly, here is one
idea: (* Make sure your MyFunction is not unbounded *) mydata=RandomInteger[{1,9},{10,2}] {{7,8},{9,4},{5,7},{4,3},{2,2},{2,7},{8,5},{9,1},{6,5},{5,=
7}} const = Thread[mydata.{x,y}>0] { 7 x+8 y>0, 9 x+4 y>0, 5 x+7 y>0, 4 x=
+3 y>0, 2 x+2 y>0, 2 x+7 y>0, 8 x+5 y>0, 9 x+y>0, 6 x+5 y>0, 5 x+7 y>0 } My=
Function[x_,y_]:=-3x^2-4y+3 NMaximize[{MyFunction[x,y],const}, {x,y} ] {3=
.10884, {x->0.190508,y->-0.0544307} } = = = = = = = = = =
= HTH :>) Dana DeLouis Mac & Mathematica 8 = = = = = = = =
= = = On Thursday, September 27, 2012 3:14:09 AM UTC-4, Felipe wrote:=
 > Hi, > > > > I am trying to maximize a function using NMaximize and I hav=
e a large list of constraints that I would like to write with a loop or as =
an array. > > > > It looks like the following: > > > > NMaximize[{myfunctio=
n[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" ar=
ray. 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. > > > > T=
hank you very much for your help > > Felipe

[toc] | [prev] | [next] | [standalone]


#12043

Fromfelipe.benguria@gmail.com
Date2012-10-11 08:40 +0000
Message-ID<k560m9$ep9$1@smc.vnet.net>
In reply to#11897
Thank you very much for all your help, this was really helpful.

felipe







El jueves, 27 de septiembre de 2012 23:10:29 UTC-4, Dana DeLouis  escribi=F3:
> > .. if mydata is an array with two columns and 100 rows, I would have 100 constraints, which are too many to enter manually. 
>
>
>
> > .. x*mydata[[1,row,1]] + y*mydata[[1,row,2]] >0
>
>
>
> Hi.  If I understood your question correctly, here is one idea:
>
> (* Make sure your MyFunction is not unbounded *)
>
>
>
> mydata=RandomInteger[{1,9},{10,2}]
>
>
>
> {{7,8},{9,4},{5,7},{4,3},{2,2},{2,7},{8,5},{9,1},{6,5},{5,7}}
>
>
>
> const = Thread[mydata.{x,y}>0]
>
>
>
> {
>
> 7 x+8 y>0,
>
> 9 x+4 y>0,
>
> 5 x+7 y>0,
>
> 4 x+3 y>0,
>
> 2 x+2 y>0,
>
> 2 x+7 y>0,
>
> 8 x+5 y>0,
>
> 9 x+y>0,
>
> 6 x+5 y>0,
>
> 5 x+7 y>0
>
> }
>
>
>
> MyFunction[x_,y_]:=-3x^2-4y+3
>
>
>
> NMaximize[{MyFunction[x,y],const}, {x,y} ]
>
>
>
> {3.10884, {x->0.190508,y->-0.0544307} }
>
>
>
> = = = = = = = = = =
>
> HTH  :>)
>
> Dana DeLouis
>
> Mac & Mathematica 8
>
> = = = = = = = = = =
>
>
>
>
>
>
>
>
>
> On Thursday, September 27, 2012 3:14:09 AM UTC-4, 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web