title: How would I modify my mathematica module to detect all minima of a polynomial with degree n?
body: <p>As of right now my module is able to detect the minima closest to the input point given.
  The module:</p>
  <pre><code>Newton[x0_, fun_] := Module[{der, xcurlist = {x0}, xold = x0 - 1, xcur = x0, deltax, deltay, MinimaList={} ii = 1}, 
   Monitor[While[ii++ &lt; 1000 &amp;&amp; xold != xcur,
     xold = xcur;
     der = (fun[xcur + .001] - fun[xcur])/.001;
     deltax = .001*Abs[der];
     deltay = -deltax*der;
     If[Abs[deltay] &gt; .1, deltay = .1*Sign[deltay]];
     xcur = xcur + deltay;
     AppendTo[xcurlist, xcur]];, 
     xcur];
   AppendTo[MinimaList,xcurlist[[-1]]]]
  </code></pre>
  <p>The function I'm testing has 2 minima:</p>
  <pre><code>k[x_] := 1 - 2 x^2 + 3 x^3 + 4.7 x^4
  </code></pre>
  <p>It's plot:</p>
  <p><a href="https://i.stack.imgur.com/vLbtf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vLbtf.jpg" alt="enter image description here" /></a></p>
  <p>(Note: my module only gets close to the minima and approximates it. This is something I'll work on fixing myself but for right now I'd like to get the module to detect both minima)</p>
  <p>It's finding the minima by approaching the function's derivative==0 of course</p>
  <p>Right minima:</p>
  <pre><code>Newton[2,k]
  </code></pre>
  <p>I get the rightmost minima approx of x~0.3004</p>
  <p>Actual value by using FindRoot of k'[x]==0 is 0.280421</p>
  <p>Left minima:</p>
  <pre><code>Newton[-1,k]
  </code></pre>
  <p>I get the left minima approx of x~-0.7637</p>
  <p>Actual value by using FindRoot of k'[x]==0 is -0.759031</p>
  <p>But I logically want it to detect that there are 2 minima for this polynomial, and n minima for any other degree polynomial. Once given a starting point it will run 1000 iterations until it approaches the first minima, then set the point after the minima as a new starting point and find the next one so that it gets 3 values to match the k'[x] degree. One of those 3 being the local maxima.
  Another obstacle is ignoring the maxima which I thought maybe an IF loop would help with by detecting whether k'[x-&gt;]&lt;0 (x to the right of the maxima) and k'[&lt;-x]&gt;0 (x to the left of the maxima) would mean the point between is a local maxima and then be removed from the minima list. However I haven't gotten anything to work.
  Another idea is once it can detect all points where k'[x]==0 it should make 3 separate lists. Then remove the maxima. Finally with what's left we have List[[-1]] of the two lists append to the final Minima list and the minima list is the output.</p>
  <p>So <code>AppendTo[MinimaList,xcur[[-1]]]</code> for each iteration at the end of the module works.</p>