I would like to know how can I plot the extrema of polynomial functions. I know how to take the derivative but I don't know how to plot it.

  • 1
    $\begingroup$ Welcome to Mathematica.SE! It is helpful to include more information in your post: for instance, a sample polynomial to work with (correctly typeset in code blocks), an explanation of what you mean to "plot the extrema" (are you showing points?), and what you've tried so far (so that we can get an idea of how much Mathematica you know or where you're going with the question). $\endgroup$ – march Apr 12 '18 at 16:58
  • $\begingroup$ That's the problem, I don't have a sample polynomial, it has to work for all polynomial function. There has to be a window, where you can write the function. I need show the points. I am beginner in Mathematica. $\endgroup$ – Lucy Apr 12 '18 at 17:14
  • 3
    $\begingroup$ I mean, there's a lot to do then. When writing code, do a specific case first. Once you do that, then you can generalize. Choose a polynomial. Learn to plot it by looking up the documentation for Plot. Learn how to use Solve to get the extrema of the polynomial. Learn how to make a plot with points using ListPlot. You need to take this in steps. StackExchange is not designed as a tutoring service but rather as something that can answer specific, targeted questions. $\endgroup$ – march Apr 12 '18 at 17:18

Given the general question, here's a general solution. Generality has its price, in terms of

polyextremaplot::nox = "No extrema.";
polyextremaplot[p_] := 
 Module[{x = Variables[p], dp, cps, dom, range},
  (dp = D[p, x];
    cps = DeleteDuplicates@Flatten[Values@NSolve[dp == 0, x, Reals]];
     0, Message[polyextremaplot::nox],
     1, dom = MinMax[Values@NSolve[p == #, x, Reals] & /@ ((p /. Thread[x -> cps])+{-1,1})],
     _, dom = MinMax[Values@NSolve[p == #, x, Reals] & /@ MinMax[p /. First@x -> cps]]
    Plot[p, Evaluate[Join[x, dom]], 
      Epilog -> {Red, PointSize[Large], Point@Transpose@{cps, p /. First@x -> cps}}] /; 
     Length@cps > 0) /; Length@x == 1

polyextremaplot[x^6 - 7 x^4 + 11 x^2 + x]

Mathematica graphics


Mathematica graphics


polyextremaplot::nox: No extrema.

(*  polyextremaplot[x]  *)

It wasn't immediately clear to me what to do when the polynomial is constant, since there is an extremum at every point; so it just remains unevaluated. PlotStyle -> Red, I suppose, is an option.

| improve this answer | |

The problem you bring up in your question is not difficult for an experience Mathematica user, but is rather much for a beginner to tackle.

Here is some code that I hope will get you started. There are issues -- and the are big ones -- that I leave for you to address. I will discuss them below. I am dealing here with the issues of accepting input and displaying a plot of the expression the user inputs. This code will accept an expression from an InputField, do some checks to see it is really a polynomial (are the checks sufficient?) and plot the polynomial if it passes the tests. I am making the code as simple as I can, so the user interface it creates doesn't look very pretty. Mathematica has a lot functions that can be used to prettify the user interface, but I think applying them would confuse you more than it would help.

  DynamicModule[{poly = Null},
           poly === Null, "",
           FreeQ[poly, x], "Not a polynomial in x",
           PolynomialQ[poly, x], Plot[poly, {x, -10, 10}],
           True, "Not a polynomial"]],
       "Enter a polynomial in x",

Here are some screen shots what the code produces.





Issues remaining for you to address

  1. After the polynomial is vetted, find the extrema.
  2. Use the found extrema to set the plot range so the extrema will show up in the plot.
  3. In an Epilog option given to Plot, draw points or vertical lines or both to show the extrema.
| improve this answer | |

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