The gradient function is a simple way of finding the slope of a function at any given point.
Usually, for a straight-line graph, finding the slope is very easy. One simply divides the "rise" by the "run" - the amount a function goes "up" or "down" over a certain interval. For a curved line, the technique is pretty similar - pick an interval, and calculate the amount of "rise" or "fall" the graph undergoes over this interval. We want to make the interval rather small, however - otherwise we can end up with some pretty funny values!
Take, for instance, the function of sin(x). We know that
- #sin(0) = 0#
- #sin(pi) = 0#
If we were to calculate rise/run in this case, we'd get #(0-0)/(pi-0)#, giving us a slope of 0. But we know that's not the case, because the graph of sin(x) behaves very differently! So we need to make the interval as small as possible in order to make the gradient function work for us.