0
$\begingroup$
pts = {{1.5, 1.5}, {1.5, -1.5}, {2.5, 0}, {2.5, 1.94}, {2.5, -1.94}, {-2.5, 0}, {2, 2},
     {-2, 2}, {2, -2}, {-2, -2}, {2.5, 2}, {-2.5, 2}, {-2.5, -2}, {2.5, -2}};

ContourPlot[{y^4 - 3 x y^2 + x^3}, {x, -2.5, 2.5}, {y, -2, 2}, 
     Contours -> {Automatic, 50}, BoundaryStyle -> Directive[Red, Thick], Frame -> False, 
     ContourShading -> None, Axes -> True, AxesLabel -> {x, y},
     PlotRange -> {{-3, 3}, {-2.5, 2.5}}, LabelStyle -> Directive[Blue, Bold], 
     Epilog -> {PointSize[0.015], Green, Point[#] & /@ pts, Black, 
               Text["-1.6875", "-1.6875", "15.625", "15.625", "1.5625", "-1.5625",
                "0", "32", "0", "32", "1.625", "30.375", "30.375", "1.625"] & /@ pts, 
     PlotLegends -> "Expressions"}]`

enter image description here

My problem is now that I have more than 2 points. And (almost) every point has a different value. Example

{1.5,1.5} shall be named -1.6875

{1.5,-1.5} shall be named -1.6875

{2.5,0} shall be named 15.625

{2.5,0} shall be named 1.5625

It continues this way.

PlotLegends shall show the Expressions (Min, Max, Saddle point). Min, Max and Saddle point shall have three different colors. The points you pick don't matter. I simply want to know how it's done. Take some for Min, some for Max and one for the Saddle point. But don't confuse the right "value" as a text output (it shall be automatic the right form)

| improve this question | | | | |
$\endgroup$
  • 1
    $\begingroup$ Aren't you worried that, by the looks of the image you uploaded, you are getting error messages ? And you are not, judging by the post, investigating what caused them $\endgroup$ – Sektor May 29 '15 at 19:15
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 May 29 '15 at 19:16
  • $\begingroup$ Perhaps MapThread could be of help (instead of /@). And perhaps PointLegend[{Red, Green, Blue}, {"Min", "Max", "Saddle"}]. -- Some parts are not completely clear. You simply want to know how what is done? And I don't understand the last sentence. Can you help? $\endgroup$ – Michael E2 May 29 '15 at 19:23
  • $\begingroup$ Considering your recent question, maybe it is not a good idea to label all points with their values on the plot. You can use your color code and label them 1,2,3, and have a separate table to write values. $\endgroup$ – Mahdi May 29 '15 at 19:56
1
$\begingroup$

EDIT: Added legends for max, min, and saddle points.

pts = {
   {1.5, 1.5}, {1.5, -1.5}, {2.5, 0},
   {2.5, 1.94}, {2.5, -1.94}, {-2.5, 0},
   {2, 2}, {-2, 2}, {2, -2}, {-2, -2},
   {2.5, 2}, {-2.5, 2}, {-2.5, -2},
   {2.5, -2}};

f[x_, y_] = y^4 - 3 x y^2 + x^3;

The function is symmetric in y

f[x, y] == f[x, -y]

True

FindMaximum[{f[x, y], -2.5 <= x <= 2.5, -2 <= y <= 2},
  {x, y}] // Rationalize[#, 10^-7] &

{32, {x -> -2, y -> 2}}

maxPts = {{x, y}, {x, -y}} /. %[[-1]]

{{-2, 2}, {-2, -2}}

FindMinimum[{f[x, y], -5/2 <= x <= 5/2, -2 <= y <= 2},
  {x, y}, WorkingPrecision -> 50] // N

{-1.6875, {x -> 1.5, y -> -1.5}}

minPts = {{x, y}, {x, -y}} /. %[[-1]]

{{1.5, -1.5}, {1.5, 1.5}}

Solve[{D[f[x, y], x] == 0, D[f[x, y], y] == 0,
    -2.5 <= x <= 2.5, -2 <= y <= 2}, {x, y}] // Union // Quiet

{{x -> 0, y -> 0}, {x -> 1.5, y -> -1.5}, {x -> 1.5, y -> 1.5}}

saddlePts = {{x, y}} /. %[[1]]

{{0, 0}}

otherPts = Complement[pts, maxPts, minPts, saddlePts];

Point[pts] is more efficient than Point[#]&/@pts and your syntax is wrong for Text

n = 1;
Legended[
 ContourPlot[
  f[x, y], {x, -2.5, 2.5}, {y, -2, 2},
  Contours -> {Automatic, 50},
  BoundaryStyle -> Directive[Gray, Thick],
  Frame -> False,
  ContourShading -> None,
  Axes -> True,
  AxesLabel -> {x, y},
  PlotRange -> {{-3, 3}, {-2.5, 2.5}},
  LabelStyle -> Directive[Blue, Bold],
  Epilog -> {
    PointSize[0.015],
    Darker[Green],
    Point[otherPts],
    Text[
       Style[ToString[f @@ #],
        Bold,
        Darker[Green],
        Background -> Yellow],
       #, {0, (-1)^(n++) 1.5}] & /@
     otherPts,
    Red,
    Point[maxPts],
    Text[
       Style[ToString[f @@ #],
        Bold,
        Red,
        Background -> Yellow],
       #, {0, (-1)^(n++) 1.5}] & /@ maxPts,
    Blue,
    Point[minPts],
    Text[
       Style[ToString[f @@ #],
        Bold,
        Blue,
        Background -> Yellow],
       #, {0, (-1)^(n++) 1.5}] & /@ minPts,
    Lighter[Purple],
    Point[saddlePts],
    Text[
       Style[ToString[f @@ #],
        Bold,
        Lighter[Purple],
        Background -> Yellow],
       #, {0, (-1)^(n++) 1.5}] & /@ saddlePts}],
 PointLegend[
  {Red, Lighter[Purple], Blue},
  {"Max", "Saddle", "Min"}]]

enter image description here

| improve this answer | | | | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.