1

Hello everybody I try to find ALL the maxima of a function and plot the points where the maxima are.

The Function is:

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);

Of course this is a 3D function but i satisfied also if someone give me a code to find all maxima with the 2D version of the function. I put a graph of the function.

points1=Table[{x, 2*U[x, 0, a]}, {x, -1.5, 1.5,0.005}];

ListPlot[points1, Joined->True,PlotRange->{{-1.5,1.5},{-5.5,-3.0}},

AxesLabel->{"x","cost. di Jacobi"}]

I saw a similar post but with a more complex function so i can't understand how modify the code: https://mathematica.stackexchange.com/questions/5575/how-to-find-all-the-local-minima-maxima-in-a-range .

Some one can help me? Thanks.

4

1 回答 1

0

我终于用最大化解决了二维问题。看看我是如何解决问题的!

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]]
]
于 2013-03-08T03:11:41.220 回答