title: Determine extrema of function
body: <p>I'm running into an issue in which the minima is not being correctly set. The maxima is setting perfectly, but I know that the minima should be less than 0. Running this snippet, it seems like the minima is never being set. Any ideas?</p>
  
  <p>edit: The curve points should be from -1 to 3. Here's an image:
  <a href="https://i.stack.imgur.com/IgId8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IgId8.png" alt="The curve"></a></p>
  
  <pre><code>public class FindingExtrema {
      public static void main(String[] args) {
          double lowestPoint = 0;
          double highestPoint = 0;
          double y;
  
          double x = -1;
          int timesCalculated = 0;
  
          while (x &lt;= 3) {
              y = run(x);
  
              if (y &lt; lowestPoint) {
                  lowestPoint = y;
                  System.out.printf("y: %1$.5f", y);
              }
  
              if (y &gt; highestPoint) {
                  highestPoint = y;
              }
  
              x += .00001;
              timesCalculated++;
          }
  
          System.out.println("Done!");
          System.out.printf("Lowest: %1$.5f, Highest: %2$.5f; Calculated %3$d times\n", lowestPoint, highestPoint, timesCalculated);
      }
  
      private static double run(double x) {
          return Math.cbrt(2 * x) - Math.sqrt(8 * x) + x + 16;
      }
  }
  </code></pre>