# Plot Epilog FindMaximum

So I have this:

a=14;
max = FindMaximum[x^3 - a x^2 - x + 1, {x, -2, 15}]
(* {1.01781, {x -> -0.0355787}}*)


And I plotted this:

Plot[f1[a, x], {x, -.5, .5}, Epilog ->
{PointSize[Medium], Red, Point[{-0.0355786613147075, 1.0178118484082224}]}]


But it's not neat enough. So I tried to put in max in the commands.

Plot[f1[a, x], {x, -.5, .5}, Epilog -> {PointSize[Medium], Red, Point[{max}]}]


But it failed since max

Coordinate {1.0178118484082224, {\$CellContextx -> -0.0355786613147075}} should be a pair of numbers, or a Scaled or Offset form.


It's easy when you apply slots and rules:

point = {x /. Last[#], First[#]} &@max;
a=14;
f1[a_, x_]:= x^3 - a x^2 - x + 1;
Plot[f1[a, x], {x, -.5, .5},
Epilog -> {PointSize[Medium], Red, Point[point]}, Frame -> True,
FrameLabel -> {"x", "\!$$\*SubscriptBox[\(f$$, $$1$$]\)(a,x)"},
BaseStyle -> Directive[FontSize -> Medium]]


• I don't understand: point = {x /. Last[#], First[#]} &@max; you're creating list, but the # &@max is what I don't understand. – Onizuka Sep 22 '14 at 9:42
• This basically means {apply the rule from the last element of # to x, take the first element of #}, where # is an argument and & ends a definition of a function. @ works almost the same as [] so, for instance, Sin[x] is the same as Sin@x (but in general @ has different evaluation order, take a look on its documentation). Try to read sth about slots (#), maybe it will clear things out for you. reference.wolfram.com/language/ref/Slot.html – Gregory Rut Sep 22 '14 at 9:56
a = 14;
f[a_, x_] := x^3 - a x^2 - x + 1;
max = FindMaximum[f[a, x], {x, -2, 15}];

pnt = Reverse[Last @@@ max];
Plot[f1[a, x], {x, -.5, .5}, Epilog -> {PointSize[Large], Red, Point[pnt]}, Frame -> True]


Alternatively, you can use Mesh instead of Epilog:

Plot[f1[a, x], {x, -.5, .5}, Frame->True, Mesh->{{{pnt[[1]], Directive[PointSize[.03], Blue]}}}]
(* you can also use max[[2, 1, -1]] instead of pnt[[1]] *)


• Nice use of Last @@@ max. I don't see other people using that property often enough. – Mr.Wizard Sep 20 '14 at 7:41
• @Mr.W, recently used in this answer to a question marked as duplicate. – kglr Sep 20 '14 at 11:43

Yet another method is a destructuring pattern:

max /. {y_, {_ -> x_}} :> {x, y}

{-0.0355787, 1.01781}


For a more complete handling see: Replacing more than one element from a Sublist