Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'find ALL local maxima of a 3d function' topicStudent Support Forum > General > "find ALL local maxima of a 3d function"

Help | Reply To Topic
Author Comment/Response
federico
03/07/13 9:19pm

hello everybody i try to find ALL maxima of a 3d function. I solve (with maximize) the 2d problem with the follow code but i can't understand how to solve the 3d one.

a=0.23;
J=-3.5;
U[x_,y_,a_]:=-((1-a)/Sqrt[(x-a)^2+y^2])-a/Sqrt[(x+1-a)^2+y^2]- 0.5*(x^2+y^2);

f[x_] := U[x, 0, a];
g[x_] := J;

{max1,val1} = Maximize[{U[x,0,a], x < a-1}, x];

{max2,val2} = Maximize[{U[x,0,a], a-1 < x < a}, x];

{max3,val3} = Maximize[{U[x,0,a], x > a}, x];

sol = x /. NSolve[g[x] == f[x] && -1.5 < x < 1.5, x];

Show[
Plot[{f[x], g[x]}, {x, -1.5, 1.5},AxesLabel->{"x","cost. di Jacobi J(x,a)"},
Epilog -> {
{Red, PointSize[0.025],
Point[{x /. val1, max1}],
Point[{x /. val2, max2}],
Point[{x /. val3, max3}],
Text["\!\(\*SubscriptBox[\(L\), \(1\)]\)",{x /. val1, max1-0.4}],
Text["\!\(\*SubscriptBox[\(L\), \(2\)]\)",{x /. val2, max2-0.4}],
Text["\!\(\*SubscriptBox[\(L\), \(3\)]\)",{x /. val3, max3-0.4}]},
{Black, PointSize[0.025],
Point[{a, -6.0}],
Point[{a-1, -6.0}],
Text["Cost. di Jacobi \!\(\*SubscriptBox[\(J\), \(0\)]\)",{1.0, J-0.2}]}
}
],
ListPlot[{#, g[#]} & /@ sol, PlotStyle -> PointSize[Large]]
]

THANKS to all you!

URL: ,
Help | Reply To Topic