In your experience with mathematics thus far, you have most likely come across the task of calculating the slope between two points. Whether you know it as "rise over run" or "change in y over change in x", the formula

will give you the slope between points $(x_1, y_1)$ and $(x_2, y_2)$. So if, for instance, we were to calculate the slope between two points on $f(x) = x^3/2$, say (0, 0) and (2, 4), we would find that by the formula, (4 - 0)/(2 - 0) gives us a slope of 2, as pictured on the following graph. For a purpose that will later be revealed, however, what if we were to find the slope of the function at a single point -- at (1, 1/2)? Such is the nature of the tangent line problem that we are about to explore, and is one of the basic questions of calculus.

Rather than simply generating a static graph this time, we'll be doing a bit of manipulation. Evaluate the following code:

In the graph, the straight line that passes through the two points is called a **secant** line -- we can say that it is an approximation of the function's slope at the point (1, 1/2), albeit not a very good one. What we want is a line tangent to the function at (1, 1/2) -- one that has a slope equal to that of the function at (1, 1/2).

To attain a better approximation of the slope at that point, let's try decreasing the distance between the two points at either side of it. In the first cell of your worksheet, change $x_1$ to 0.5 and $x_2$ to 1.5 and evaluate. Your graph should now look something like the following image:

As you can see, the secant line in this graph still does not pass through the desired point of (1, 1/2), but at least we are getting closer. Now, try setting $x_1$ as 0.999 and $x_2$ as 1.001 and again evaluate the cell. Aside from looking cramped, what else can you observe about this graph? "Aha!" you surely say, it looks like the slope at (1, 1/2) is just about equal to 1.5000005. We could, of course, repeat this process in perpetuum, since when only a billionth of a unit separates the two points, there is little doubt that the calculated slope does, in fact, approximately equal the slope of $f(x) = x^3/2$ at (1, 1/2).

Let us skip that theoretical headache, however, and consider a much faster (and even more accurate!) method. Look again at the formula for calculating slopes, this time in a slightly altered form:

Rather than ignoring the relationship between the two points, as in the first form, this formula relies upon it. The symbol $y_2$ is now f(x + h), and $y_1$ is f(x). The major difference here, though, is that $x_2$ has been replaced by the first x plus some change "h". The slope formula's premise still stands, however, as the new form does in fact calculate change in y over change in x.

So what can we do with this new formula, you ask? Well, what we would like to do is to make the change in x (designated by h) equal to zero in order to find the function's slope at a single point. Exchanging 0 for h does not work well, however, since that would make the formula simply (f(x + 0) - f(x))/0, which is not of much help (0/0 = ?). Let us consult SageMath, though, and see if there is a way to factor out h before setting it equal to zero. Evaluate following code:

The result should look like this: `1/2*((h + x)^3 - x^3)/h`

. With h still in the denominator, though, replacing it with zero would not be a good idea. Luckily, SageMath has a way for us to pull all variables from the denominator to the numerator, which is just what we need. Evaluate the following:

The result should be `1/2*h^2 + 3/2*h*x + 3/2*x^2`

. Now that h is in the numerator, replacing it with zero will give us a formula for the function's slope at any value of x. To realize this result, add ".subs(h=0)" without the quotes to the end of rational_simplify() in the last entry and again evaluate the cell. And there you have it! By describing the change in x as a number 'h', we were able to simplify the formula for slope and replace h with zero in order to find that the slope of the function's tangent line at any x-coordinate is equal to $3x^2/2$. This resulting expression is known as the derivative of $f(x) = x^3/2$. You'll learn more about derivatives in the next section, but for now you should know that a function's derivative measures rate of change at a point.

To complete what we had originally set out to do, plug in a value of 1 for x, now, and you will see that the slope of the line tangent to the point (1, 1/2) on $f(x) = x^3/2$ is 3/2. This confirms our earlier experimentation with numerical analysis in addition to being an exact solution. If we were to write an equation for this tangent line in slope-intercept form, it would be

It's very important to remember that the equation for a tangent line can always be written in slope-intercept or point-slope form; if you find that the equation for a tangent line is $y = x^{4*x^2+e} + \sin{x}$ or some such extreme, something has gone (horribly) wrong. The slope of a tangent line will always be a constant.

You probably wouldn't be surprised to learn that this symbolic process involved a limit, specifically "the limit of (f(x + h) - f(x)))/h as h approaches zero." The slope that we found is also known as the derivative of f(x) at x=1. Look at how the tangent line lies against the graph of $f(x) = x^3/2$:

Now that we have an exact methodology for computing the slope of a tangent line, consider the function

What is the equation for the line tangent to (-2, g(-2))? The slope of the tangent line can be found using the function's derivative:

Plug in -2 for x, then write an equation for the tangent line:

Here is another comparison:

Use the limit process to find the equation of the line tangent to the indicated point.

Previous (Slant Asymptotes) Next (The Definition of Derivative)