Re: RE: How find the max value of
- To: mathgroup@smc.vnet.net
- Subject: [mg11877] Re: [mg11841] RE: [mg11819] How find the max value of
- From: "Jürgen Tischer" <jtischer@pitagoras.univalle.edu.co>
- Date: Fri, 3 Apr 1998 03:45:34 -0500
I'm afraid Ted, you didn't get the point. The problem isn't about getting max or min, the problem is about searching for an extreme value on a non-open set. To tell the truth, apart from doing it the hard way (first search inside using calculus methods, then search along the border, then compare what you got) I can't see a way how to do it. J|rgen -----Original Message----- From: Ersek_Ted%PAX1A@mr.nawcad.navy.mil To: mathgroup@smc.vnet.net <Ersek_Ted%PAX1A@mr.nawcad.navy.mil> Subject: [mg11877] [mg11841] RE: [mg11819] How find the max value of > >barreto"@fec.unicamp.br wrote: > ---------- >| >|w[x_,y_] := Sin[x]*Cos[y]; >| >|and I need to get the max value of the function in a determinate >|interval >| >|for example >| >| >|{x,0,1},{y,-1,0} >|How can I do that? >| > >Find the minimum of ( -w[x,y] ) and then change the sign. > >You want to find a global minimum. In order to do that FindMinimum >needs to start sufficiently close to the global minimum. Otherwise it >will likely converge on a local minimum that isn't the global minimum. >You can do that by sampling the function at the points on a grid, and >start at the point where ( -w[x,y] ) is the greatest. In the lines >below I hacked out some code to do this. If you like you can >implement this in a package. > >In the lines below use it my code on a less trivial example. For this >example FindMinimum would have worked if it started at almost any >point in the given interval. For other examples it will be more >important to sample at the points in a grid. > >Ted Ersek >_______________________________ > >In[1]:= >w[x_,y_] := Sin[x+Pi/3]*Cos[y+Pi/3]/(x^2+1/2) > >In[2]:= >Module[{pnts, z, biggest, index, start, result}, ( > pnts=Table[{x,y,w[x,y]},{x,0,2,0.1},{y,-2,0,0.1}]; > pnts=Flatten[pnts,1]; > z=Part[Transpose[pnts],3]; > biggest=Max[z]; > index=Position[pnts,biggest]; > index=Part[index,1,1]; > start=Part[pnts,index]; > result=FindMinimum[-w[x,y],{x,start[[1]]},{y,start[[2]]}]; > result/.{dip_,xyvalues_}->{-dip,xyvalues} > )] > > >Out[2]= >{1.788104802108598, {x -> 0.1118975014816867, > y -> -1.047197650578143}} > >