Parametric Plots and Tangents at a Given t-value
In this example, we plot a parametrized curve, meaning that the variables x and y both depend on a third variable, or parameter t, and a tangent line. We will plot the curve parametrized by x = t3 – 3t2, y = t3 – 3t on the domain t in [-2,3] and plot the tangent line at t=-2. After loading the symbolic package into Python, we define x and t as a symbolic variables using the symbols command, and define the expressions for xt and yt (since we will need the symbolic variable x for the tangent line equation). After executing the command matplotlib notebook to put our graph in the Jupyter notebook, we plot the parametrized curve. For parametric equations, we use the command plot_parametric. According to the help documentation online, the options include the x expression, the y expression, then a tuple for the t domain. Now we follow our strategy for the tangent line: find the derivative using the formula dy/dx = (dy/dt) / (dx/dt) using the diff command. Then, substitute the t value into the derivative (for the slope), xt (for x0), and yt (for y0) using subs. Finally, define a variable for the tangent line equal to the expression y0 + m*(x-x0). We can plot this equation using the symbolic plot command. Since we used different plot commands, we put the graphs together by naming the original plot a variable such as pcurve, then using .extend at the end of the variable, including our new plot command as an option, then finally use .show() to show the new plot.