Lesson 7 of 18
Gradient Magnitude
The Gradient
The gradient of is the vector of its partial derivatives:
The Gradient Points Uphill
The gradient vector always points in the direction of steepest ascent. Its magnitude tells you how steep that ascent is.
Key Facts
- at critical points (local minima, maxima, saddle points)
- The gradient is perpendicular to level curves (contour lines)
- Moving against the gradient is steepest descent — the basis of gradient descent in machine learning
Examples
For :
- At :
For :
- At :
Your Task
Implement double gradient_magnitude(double (*f)(double, double), double x, double y, double h) that computes at using central differences for the partial derivatives.
TCC compiler loading...
Loading...
Click "Run" to execute your code.