Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 4928

Tangent Lines

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

y2y1x2x1\dfrac{y_2-y_1}{x_2-x_1}

will give you the slope between points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). So if, for instance, we were to calculate the slope between two points on f(x)=x32f(x) = \dfrac{x^3}{2}, say (0,0)(0, 0) and (2,4)(2, 4), we would find that by the formula, 4020\dfrac{4 - 0}{2 - 0} gives us a slope of 22, 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,12)(1, \dfrac{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. It is highly recommended that you follow along. In a new worksheet called 06-Tangent Lines, copy/paste the following code and evaluate it.

x1 = 0 # Declare x values of interest x2 = 2 def f(x): # Define quadratic function return (x^3)/2 y1 = f(x1) # Solve for y values of quadratic at given x values y2 = f(x2) slope = (y2-y1)/(x2-x1) # Define slope that passes through points of interest p = plot(f(x), x, 0, 3) # Generate a plot of the quadratic function, and points of interest pt1 = point((x1, y1), rgbcolor=(1,0,0), pointsize=30) pt2 = point((x2, y2), rgbcolor=(1,0,0), pointsize=30) d = 3 # Generate a line that passes through l = line([(x1-d, y1-d*slope), (x2+d, y2+d*slope)], rgbcolor=(1,0,0)) t1 = text("(%s, %s)" % (float(x1), float(y1)), (x1+0.5, y1-0.8), rgbcolor=(1,0,0)) # Generate labels t2 = text("(%s, %s)" % (float(x2), float(y2)), (x2+0.5, y2-0.8), rgbcolor=(1,0,0)) t3 = text("slope: %s" % float(slope), ((x1+x2)/2-0.5, (y1+y2)/2), rgbcolor=(1,0,0)) g = p+pt1+pt2+l+t1+t2+t3 # Combine and show previously generated graphs and points with given bounds g.show(xmin=0, xmax=3, ymin=-1, ymax=9)

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,12)(1, \dfrac{1}{2}), albeit not a very good one. What we want is a line tangent to the function at (1,12)(1, \dfrac{1}{2}) -- one that has a slope equal to that of the function at (1,12)(1, \dfrac{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 x1x_1 to 0.50.5 and x2x_2 to 1.51.5 and evaluate. Your graph should now look something like the following:

As you can see, the secant line in this graph still does not pass through the desired point of (1,12)(1, \dfrac{1}{2}), but at least we are getting closer. Now, try setting x1x_1 as 0.9990.999 and x2x_2 as 1.0011.001 and again evaluate the cell. Aside from looking cramped, what else can you observe about this graph? Ah ha! you surely say, it looks like the slope at (1,12)(1, \dfrac{1}{2}) is just about equal to 1.50000051.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)=x32f(x) = \dfrac{x^3}{2} at (1,12)(1, \dfrac{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:

f(x+h)f(x)h\dfrac{f(x+h)-f(x)}{h}

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

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

def f(x): # Set f(x) as x^3/2 return (x^3)/2 var('x, h') # Initialize variables x and h (f(x + h) - f(x))/h # Evaluate (f(x + h) - f(x))/h
(x, h) 1/2*((h + x)^3 - x^3)/h

The result should be 3x2+3hx+h22\dfrac{3x^2 + 3hx + h^2}{2}. With hh 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. In another cell, type and evaluate the following:

((f(x + h) - f(x))/h).rational_simplify()
1/2*h^2 + 3/2*h*x + 3/2*x^2

The result should be 3x2+3hx+h22\dfrac{3x^2+3hx+h^2}{2}. Now that hh is in the numerator, replacing it with zero will give us a formula for the function's slope at any value of xx. 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 xx as a number 'hh', we were able to simplify the formula for slope and replace hh with zero in order to find that the slope of the function's tangent line at any x-coordinate is equal to 3x22\dfrac{3x^2}{2}. This resulting expression is known as the derivative of f(x)=x32f(x) = \dfrac{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 11 for xx, now, and you will see that the slope of the line tangent to the point (1,12)(1, \dfrac{1}{2}) on f(x)=x32f(x) = \dfrac{x^3}{2} is 32\dfrac{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

y=3x21y=\dfrac{3x}{2}-1.

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=x4x2+e+sin(x)y = x^{4x^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\dfrac{f(x + h) - f(x)}{h} as hh approaches zero." The slope that we found is also known as the derivative of f(x)f(x) at x=1x=1. Look at how the tangent line lies against the graph of f(x)=x32f(x) = \dfrac{x^3}{2}:

# Plot the original function with its tangent line and a point to show where they touch (plot(x^3/2, x, 0, 2)+plot(3*x/2-1, 0, 2, rgbcolor='red')+point((1, 1/2), \ rgbcolor='black', pointsize=30)).show(xmin=0, xmax=2, ymin=-1, ymax=4)

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

g(x)=3xg(x)=\dfrac{3}{x}

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

g(x)=limh0g(x+h)g(x)h=limh03x+h3xh=limh03xx2+xh3x+3hx2+xhh=limh03hx2+xhh=limh03x2g'(x)=\underset{h\to0}{\rm{lim}}\dfrac{g(x+h)-g(x)}{h}=\underset{h\to0}{\rm{lim}}\dfrac{\dfrac{3}{x+h}-\dfrac{3}{x}}{h}=\underset{h\to0}{\rm{lim}}\dfrac{\dfrac{3x}{x^2+xh}-\dfrac{3x+3h}{x^2+xh}}{h}=\underset{h\to0}{\rm{lim}}\dfrac{-\dfrac{3h}{x^2+xh}}{h}=\underset{h\to0}{\rm{lim}}\dfrac{-3}{x^2}

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

g(2)=3(2)2=34g'(-2)=-\dfrac{3}{(-2)^2}=-\dfrac{3}{4}, so y=34x3y = -\dfrac{3}{4}x-3

Here is another comparison:

# Plot the original function with its tangent line and a point to show where they touch. (plot(3/x, x, -3, 0)+plot(-3*x/4-3, -3, 0, rgbcolor='red')+point((-2, -3/2), \ rgbcolor='black', pointsize=30)).show(xmin=-3, xmax=0, ymin=-10, ymax=0)

Practice Problems

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

  1. f(x)=4xf(x)=4x at x=2x=2

  2. g(x)=3x2+2g(x)=-3x^2+2 at x=1x=-1

  3. x(t)=5t+3x(t)=\dfrac{5}{t}+3 at t=5t=5

To view answers, select this cell and paste it into your own sagews, and then double click on it

[Previous: Supplement: Slant Asymptotes](Slant_Asymptotes.sagews) | [To Main](Introduction.sagews) | [Next: The Definition of the Derivative](The_Definition_of_the_Derivative.sagews)