Hello! Welcome to the final lesson of our module on Matrix Calculus and Optimization.
In our last lesson, we explored the concept of convexity and saw how a positive definite Hessian matrix guarantees that a function has a "bowl" shape with a unique global minimum. We established that the gradient vector, , points in the direction of steepest ascent. This sets the stage perfectly for today's topic: now that we know which way is "uphill," how do we design an algorithm to systematically walk "downhill" and find the bottom of the bowl?
This lesson introduces Gradient Descent, arguably the most important optimization algorithm in machine learning. Your goal is to be able to formulate and apply this algorithm to find the minimum of a simple multivariate function. Mastering this is a huge step toward understanding how deep learning models are trained, as gradient descent is the engine that drives that process.
1. The Intuition: A Ball Rolling Down a Hill
Before diving into the math, let's build a strong mental model. Imagine placing a ball on a hilly landscape. The ball will naturally roll downhill. Gradient descent is the mathematical formalization of this idea. The "landscape" is our function's graph, and the "downhill" direction is determined by the gradient.
The following video provides an excellent high-level intuition for why we want to find a minimum and how gradient descent accomplishes this, all within the context of training a neural network.
Gradient descent, how neural networks learn | Deep Learning Chapter 2
The video 'Gradient descent, how neural networks learn' from 3Blue1Brown masterfully visualizes the core concept. It will help you see how finding a function's minimum is equivalent to making a model 'smarter'.
Please watch from 05:20 to 08:27. The first part (until 06:50) explains the idea for a simple 1D function. The second part extends this to a 2D function, introducing the gradient as the key to finding the 'downhill' direction.
As the video explains, the core idea is simple:
- Start at some point on the function's surface.
- Find the direction of steepest descent.
- Take a small step in that direction.
- Repeat.
The gradient, , gives the direction of steepest ascent. Therefore, the direction of steepest descent is simply its negative, .
2. Formulating the Gradient Descent Algorithm
Let's translate this intuition into a formal algorithm. We want to find the minimum of a multivariate function , where is a vector of parameters (e.g., ).
The Gradient Descent algorithm is an iterative process defined by the following update rule:
Let's break this down:
- is the vector of parameters at iteration .
- is the updated vector of parameters for the next iteration.
- is the gradient of the function evaluated at the current position .
- (the Greek letter eta) is the learning rate, a small positive scalar that controls the size of each step.
This rule simply states: "The next position is the current position, minus a small step in the direction of the negative gradient."

The following video provides a crystal-clear, step-by-step walkthrough of applying this rule, first for a single parameter and then for two parameters, which is exactly what we need for multivariate functions.
Gradient Descent, Step-by-Step
The video 'Gradient Descent, Step-by-Step' from StatQuest with Josh Starmer is one of the best explanations available. It makes the abstract update rule concrete and easy to follow.
Please watch from 04:55 to 21:55. The first part (04:55 - 15:49) meticulously details the process for finding one parameter. Pay close attention to how the derivative is used to calculate the step size and update the parameter. The second part (15:49 - 21:55) extends this to two parameters, introducing the gradient (as a collection of partial derivatives) and showing how both parameters are updated together.
3. Key Practical Considerations
The StatQuest video gave you the full mechanical picture. Now, let's focus on a few crucial details that are essential for applying the algorithm correctly.
The Algorithm's Steps
The overall process can be summarized in a simple loop.

The Importance of the Learning Rate ()
The learning rate is a critical hyperparameter—a parameter you set before the optimization begins. Its value has a huge impact on performance.
Optimization via Gradient Descent
These lecture notes from Princeton provide a concise summary of the role of the learning rate.
Please read section 3.1.3, 'Learning Rate (LR)'. The text and Figure 3.3 clearly illustrate what happens when η is too small or too large.
As the reading explains:
- If is too small: The algorithm will take tiny steps, converging very slowly.
- If is too large: The algorithm might "overshoot" the minimum and bounce around, potentially diverging instead of converging.
Finding a good learning rate is often a process of experimentation.
Simultaneous Updates
This is a subtle but critical implementation detail. When you update the parameters in your vector , you must compute all the components of the gradient first, before changing any of the parameter values.
Intuition (and maths!) behind multivariate gradient descent
This article provides a very clear explanation and analogy for why simultaneous updates are necessary.
Read the short section 'Simultaneous update'. The walking analogy is particularly insightful.
For example, to update and , you would do it like this:
Correct (Simultaneous Update):
temp1 = w1 - η * (∂f/∂w1)temp2 = w2 - η * (∂f/∂w2)w1 = temp1w2 = temp2
Note that the calculation for temp2 uses the original w1, not the newly calculated temp1.
4. Applying Gradient Descent: A Worked Example
Let's solidify this by applying the algorithm to a simple convex function: .
We know from our previous lessons that this function is a paraboloid with its minimum at .
- Function:
- Gradient:
- Update Rules:
Let's choose a starting point and a learning rate .
Iteration 1:
- Current position: .
- Calculate gradient at : .
- Calculate the step: .
- Update position: .
- Check progress: . . We've moved closer to the minimum!
Iteration 2:
- Current position: .
- Calculate gradient at : .
- Calculate the step: .
- Update position: .
If we continue this process, the point will get progressively closer to the minimum at .
Test your understanding!
Perform one step of gradient descent for the function .
Use a starting point of and a learning rate of . What is the new point ?
Show answer
-
Find the gradient:
-
Evaluate the gradient at the starting point :
-
Apply the update rule:
The new point is . Notice that in this special case, we found the exact minimum in a single step! This happened because our function is a simple quadratic and we chose a "perfect" learning rate. This is not typical in practice.
Conclusion
Congratulations on completing this crucial lesson! You now understand the mechanics of the primary algorithm that powers much of modern machine learning.
Key Takeaways:
- Gradient Descent is an iterative algorithm for finding the minimum of a function.
- The core update rule is , which involves taking steps in the direction of the negative gradient.
- The learning rate is a critical hyperparameter that controls step size; if it's too large, the algorithm can diverge, and if it's too small, it will be too slow.
- For multivariate functions, parameter updates must be done simultaneously.
Preview of the Next Lesson:
This was the last lesson in this module, but it sets up the next module perfectly. We have now mastered the tool (Gradient Descent) and the prerequisite calculus. The next step is to apply it to a real-world problem. In our next lesson, we will begin our module on applications by formulating the least squares problem for linear regression. We will define a cost function that measures how well a line fits a set of data points, and then we will use our matrix calculus skills to find the gradient of that cost function—the final piece needed to train a linear regression model using the gradient descent algorithm you learned today.