RE: 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}}