course
Every time a company sets prices to find the best profit margin, or a model adjusts its weights to shrink prediction error, the same calculus problem is running underneath: find the highest or lowest value of a function. That's what minima and maxima are about. The peaks and valleys that tell you where a function hits its extreme values.
In this article, we'll start with what extrema actually mean, separate local from global behavior, walk through finding them using derivatives, and connect it back to why any of this matters in optimization and data science. If you want to build on these ideas with hands-on practice, our Introduction to Optimization in Python course covers the computational side.
What Are Minima and Maxima?
A minimum is the lowest value a function reaches; a maximum is the highest. Together, they're called extrema (singular: extremum). On a graph, they're exactly what you'd expect: the bottoms of valleys and the tops of peaks.
One thing worth keeping clear from the start: the extremum is the function value (the y-coordinate), while the point where it occurs is the x-value. "The maximum is at x = 3" is different from "the maximum value is f(3) = 10." This distinction trips people up more than you'd think, and it shows up in exam problems and interview questions alike.
Not every function has both a minimum and a maximum. A line has neither. A parabola opening upward has a minimum but no maximum. Functions defined on open intervals can approach extreme values without ever reaching them. Extrema aren't guaranteed; they depend on the shape of the function and the domain you're working with.
Local vs. Global Minima and Maxima
Before finding extrema, it's worth getting clear on a distinction that runs through everything that follows: the difference between extrema that are locally significant and those that are globally significant. This is one of the most practically important ideas in optimization, and it's also where people most often get confused.
The difference comes down to scope. A local extremum looks at a small neighborhood around a point; a global extremum considers the entire domain.
Local minimum and maximum
A local minimum is a point where the function value is lower than all nearby values. You're at the bottom of a valley, even if a deeper valley exists somewhere else on the graph. A local maximum is a peak that's higher than its immediate surroundings, even if a taller peak exists farther away.
Picture a hiking trail with rolling hills. Each hilltop is a local maximum, and each dip between hills is a local minimum. You don't need to see the entire trail to identify them; you just compare with what's immediately around you.
Global minimum and maximum
A global minimum (also called the absolute minimum) is the single lowest value the function takes across its entire domain. The global maximum (or absolute maximum) is the single highest. A global extremum is always also a local extremum, but the reverse isn't true.
On that same hiking trail, the global maximum is the highest point on the entire route, not just the tallest nearby hill. A function can have many local extrema but at most one global minimum value and one global maximum value (though those values might occur at multiple points).
This local-versus-global distinction isn't just theoretical. It shows up directly in machine learning, where gradient descent can get stuck at local minima when searching for a global one. More on that later.
How to Find Minima and Maxima
Finding extrema follows a consistent process. You're essentially asking: where does the function stop increasing and start decreasing, or vice versa? Derivatives give you the tool to answer that precisely.
Here's the general approach:
- Compute the first derivative f'(x).
- Find the critical points, where f'(x) = 0 or f'(x) doesn't exist.
- Classify each critical point as a local minimum, local maximum, or neither.
- If you're working on a closed interval, check the endpoints too.
- Compare all candidate values to identify the absolute extrema.
We'll use one function throughout to keep things concrete: f(x) = 2x³ − 9x² + 12x − 4, defined on the interval [0, 4].
Critical Points and Extrema
A critical point of f(x) is any value of x in the domain where f'(x) = 0 or f'(x) is undefined. These are the candidates for extrema, the places where the function might change direction.
Why do extrema show up at critical points? At a smooth peak or valley, the tangent line is horizontal, so the derivative equals zero. But not every critical point is an extremum, and this matters. The classic counterexample is f(x) = x³ at x = 0: the derivative is zero, but the function doesn't change direction. It just flattens briefly before continuing upward. Points where the derivative doesn't exist also need attention. A sharp corner like the one in f(x) = |x| at x = 0 has no derivative, yet that's exactly where the minimum sits.
For our example, f'(x) = 6x² − 18x + 12 = 6(x² − 3x + 2) = 6(x − 1)(x − 2). Setting this to zero gives critical points at x = 1 and x = 2. Now we need to figure out what's happening at each one.
How to Use the First Derivative Test
The first derivative test classifies critical points by checking whether f'(x) changes sign. If the function goes from increasing to decreasing, you're at a peak. If it goes from decreasing to increasing, you're at a valley.
Positive to negative
When f'(x) switches from positive to negative as you pass through a critical point, that point is a local maximum. The function climbed up to it and then came back down.
Negative to positive
When f'(x) switches from negative to positive, the function was falling and then started rising. That critical point is a local minimum.
No sign change
If f'(x) stays positive on both sides (or stays negative on both sides), the critical point is neither a minimum nor a maximum. The function paused but didn't reverse direction, like f(x) = x³ at x = 0.
For our function, let's test the intervals around x = 1 and x = 2. Pick test points: f'(0.5) = 6(0.5 − 1)(0.5 − 2) = 6(−0.5)(−1.5) = 4.5 > 0, f'(1.5) = 6(0.5)(−0.5) = −1.5 < 0, and f'(3) = 6(2)(1) = 12 > 0. At x = 1, the derivative goes from positive to negative: local maximum. At x = 2, it goes from negative to positive: local minimum. The function values are f(1) = 1 and f(2) = 0.
The first derivative test always works, but it requires picking test points in each interval, which gets tedious fast. There's a quicker method when certain conditions are met.
How to Use the Second Derivative Test
The second derivative test works when f''(x) ≠ 0 at the critical point. Instead of checking sign changes across intervals, you evaluate the second derivative at the critical point directly.
The idea connects to concavity. If f''(c) > 0, the function is concave up at c, curving like a bowl, so the critical point sits at the bottom: local minimum. If f''(c) < 0, the function is concave down, curving like a hill, so the critical point is at the top: local maximum. If f''(c) = 0, the test tells you nothing. You'll need to fall back on the first derivative test.
For our function, f''(x) = 12x − 18. At x = 1: f''(1) = 12 − 18 = −6 < 0, confirming a local maximum. At x = 2: f''(2) = 24 − 18 = 6 > 0, confirming a local minimum. Same answers as before, but faster. The second derivative test won't always work (it fails at inflection points and some degenerate critical points), but when it does, it saves time.
How to Find Absolute Minima and Maxima on an Interval
When you're working on a closed interval [a, b] with a continuous function, the Extreme Value Theorem guarantees that both an absolute maximum and an absolute minimum exist. You're not searching in vain.
The method is called the closed-interval method:
- Find all critical points of f(x) inside the interval (a, b).
- Evaluate f(x) at each critical point.
- Evaluate f(x) at both endpoints, a and b.
- The largest value is the absolute maximum; the smallest is the absolute minimum.
For f(x) = 2x³ − 9x² + 12x − 4 on [0, 4], we already know the critical points are x = 1 and x = 2. Evaluating everywhere that matters:
f(0) = -4
f(1) = 2 - 9 + 12 - 4 = 1
f(2) = 16 - 36 + 24 - 4 = 0
f(4) = 128 - 144 + 48 - 4 = 28
The absolute minimum is f(0) = −4, and the absolute maximum is f(4) = 28. Notice the absolute maximum is at an endpoint, not a critical point. This is why you can't skip the endpoint check, and it's also the most common mistake people make. We'll get to that in the errors section.
Everything so far applies to functions of a single variable. Most real-world problems involve multiple variables, so it's worth seeing how this extends.
Minima and Maxima of Multivariable Functions
For a function f(x, y), you find critical points by setting both partial derivatives to zero: ∂f/∂x = 0 and ∂f/∂y = 0. A critical point is now a pair (x, y) rather than a single value. Classification gets trickier because there's a new possibility: saddle points, where the function curves up in one direction and down in another. Think of the center of a Pringles chip.
To classify multivariable critical points, you use the Hessian matrix, a square matrix of second-order partial derivatives. The determinant and the signs of its entries tell you whether you're at a local minimum, local maximum, or saddle point. Our Hessian Matrix tutorial goes deeper into the mechanics and shows how this connects to curvature in higher dimensions.
Minima and Maxima in Optimization and Machine Learning
If you've worked with machine learning at all, you've already been solving minima problems. Training a model means minimizing a loss function, and a loss function is just another function with minima and maxima.
Gradient descent is the workhorse here. It computes the derivative (or gradient, in multiple dimensions) of the loss function at the current parameter values, then takes a step in the direction that reduces the loss. Walking downhill on the loss surface, looking for a minimum. Our Gradient Descent in Machine Learning tutorial covers the full algorithm.
Here's where the local-versus-global distinction becomes a real engineering problem. For non-convex loss functions (which most neural networks have), gradient descent can get stuck in local minima instead of finding the global minimum. Techniques like learning rate schedules, momentum, and stochastic gradient descent help the algorithm escape shallow local minima, though guaranteeing a global minimum in non-convex problems remains an open challenge. Our Cost Functions tutorial explains how these objective functions are built and why their shape matters.
Common Mistakes When Finding Minima and Maxima
Assuming every critical point is an extremum
Not every critical point produces a minimum or maximum. Inflection points like x = 0 in f(x) = x³ have f'(x) = 0 but no direction change. Always verify with a derivative test.
Confusing local and global extrema
A local minimum is only the lowest point in a neighborhood. The global minimum could be somewhere else entirely, or at an endpoint. Don't stop after finding one local extremum.
Forgetting endpoints
On a closed interval, the absolute extrema can occur at the boundaries. The absolute maximum in our example was at x = 4, not at either critical point. Skipping endpoints is one of the most common errors in optimization problems, and I'd wager it accounts for more lost exam points than any conceptual misunderstanding.
Assuming a zero second derivative means no extremum
When f''(c) = 0, the second derivative test is inconclusive. It doesn't mean the point isn't an extremum. Consider f(x) = x⁴ at x = 0: f''(0) = 0, but x = 0 is clearly a minimum. Use the first derivative test when the second derivative test fails.
Confusing the extremum point with its value
The extremum value is f(c), not c itself. "The minimum is x = 2" when you mean "the minimum value is f(2) = 0" mixes up the input with the output. Reports and exam answers need the function value, not just the location.
Conclusion
There's a version of this topic that stops at "find where the derivative equals zero." A lot of introductory courses do exactly that, and it leaves students unprepared for the part that actually matters in practice: knowing whether you've found a local minimum or a global one, and understanding that those are very different things depending on what you're trying to do.
The calculus here is compact. Critical points, derivative tests, endpoint checks. What takes longer to internalize is the geometry underneath it: why concavity determines the shape of a minimum, why endpoints can outrank critical points, why gradient descent in a neural network is genuinely searching for a minimum on a surface that might have thousands of local ones.
For implementation, our Introduction to Optimization in Python course covers these problems computationally using SciPy and SymPy. That's where the connection between the calculus and the code becomes concrete.
Vinod Chugani began his career in Tokyo as JPMorgan's youngest Hedge Fund Sales Desk Head and later set an individual sales record at Lehman Brothers, then built a 30-country electronics distribution business past SG$100 million in revenue before pivoting to data. A Duke Economics grad and NYC Data Science Academy alum, he was one of three scholarship recipients out of 100+ applicants for Hugo Bowne-Anderson's Building AI Applications course on Maven. Today, he writes for DataCamp, KDnuggets, Machine Learning Mastery, and Statology on topics from statistics to agentic AI, and mentors data professionals at NYC Data Science Academy with over 1,000 one-on-one sessions to his name.
FAQs
What is the difference between minima and maxima?
A minimum is the lowest value a function reaches at a given point, while a maximum is the highest value. Together they're called extrema. A function can have multiple local minima and maxima, but the global (absolute) minimum is the single lowest value across the entire domain, and the global maximum is the single highest.
How do you find the minima and maxima of a function?
Take the first derivative, set it equal to zero, and solve for x to find critical points. Then use the first derivative test (check sign changes) or the second derivative test (evaluate f''(x) at each critical point) to classify each one as a minimum, maximum, or neither. On a closed interval, also evaluate the function at the endpoints.
What is the difference between local and global extrema?
A local extremum is the highest or lowest value in a small neighborhood around a point. A global (absolute) extremum is the highest or lowest value across the entire domain of the function. Every global extremum is also a local extremum, but most local extrema are not global.
Can a function have more than one global minimum?
A function can have only one global minimum value, but that value can occur at multiple points. For example, f(x) = cos(x) has a global minimum value of −1, which occurs at x = π, x = 3π, x = −π, and so on. The minimum value is unique; the locations where it occurs may not be.
What is a critical point, and is it always an extremum?
A critical point is where f'(x) = 0 or f'(x) is undefined. It's a candidate for an extremum, but not guaranteed to be one. For example, f(x) = x³ has a critical point at x = 0 (since f'(0) = 0), but it's an inflection point, not an extremum—the function doesn't change direction there.
When does the second derivative test fail?
The second derivative test is inconclusive when f''(c) = 0 at a critical point c. In that case, you need to use the first derivative test or analyze higher-order derivatives. A classic example is f(x) = x⁴, where both f'(0) = 0 and f''(0) = 0, yet x = 0 is a minimum.
Why do endpoints matter when finding absolute extrema?
On a closed interval [a, b], the Extreme Value Theorem guarantees that a continuous function has both an absolute maximum and minimum. These can occur at critical points or at the endpoints. Ignoring endpoints means you might miss the actual absolute extremum, which is one of the most common mistakes in these problems.
How are minima and maxima used in machine learning?
Training a machine learning model is an optimization problem: you minimize a loss function (or equivalently, maximize a performance metric). Gradient descent and its variants find minima of the loss function by iteratively following the negative gradient. The challenge of local versus global minima is directly relevant—non-convex loss functions can trap optimization algorithms in suboptimal local minima.



