Finding Horizontal Tangent Lines
In this example, we use Python to locate horizontal tangent lines to the curve y = (6x^2-4x^3)/2*sqrt(x^3(2-x)). We will first plot the graph using the plot command to see if there are horizontal tangent lines. If we notice the square root in the denominator, we can tell that our domain should be (0,2), and since there is a vertical asymptote at x=2, we will use the ylim option to reduce the y-range to [-10,10]. Now we see there is a point (the maximum point on the graph) where the tangent line is horizontal. Our strategy for finding the location of the horizontal tangent line (which means slope is 0) is as follows:
1) Find the derivative of the function (diff)
2) Solve where the derivative is equal to zero (solve)
If we need to review how to use these commands, we can refer to the help documentation on the 151/152 course homepage or to earlier videos addressing these specific commands. When we take the derivative, we end up with a very messy expression, so it might be better to simplify the derivative before solving. Even then, we notice that Python cannot quickly solve f’(x)=0. In this case, we first interrupt the computation by pressing the “stop” button. Now we solve it numerically using nsolve. Recall that the nsolve command requires a starting guess, but we can tell from the graph that the horizontal tangent line is near x=0.75. When we run the nsolve command, we find the horizontal tangent line occurs at about x=0.634.