Calculus 2, Lab 6: Parametric curves#

Recall that a parametric curve is given by equations \(x=f(t), y=g(t)\), for \(t\) in some domain (often a closed interval \([a,b]\)).

Using parametric equations allows us to define a wide variety of curves that would be impossible to define using the graph of a function, or an implicitly-defined function.

The main things we are interested in with parametric curves are:

  1. How to plot them (this is mostly a job for the computer)

  2. How to convert (when possible) between “rectangular” curves like \(y=x^2\) or \(\frac{x^2}{4}+\frac{y^2}{9}=1\) and parametric curves. (Converting from rectangular to parametric is called “parametrization”, and there is no unique answer for this. Converting from parametric to rectangular is called “eliminating the parameter”.)

  3. Calculating tangent and normal lines to parametric curves, and determining if a curve is “smooth”

  4. Calculating arc length (this is mostly a job for the computer)

  5. Calculating area bounded by closed curves (this is the topic of Assignment 9)

In this notebook you will learn how to plot parametric curves using SymPy and GeoGebra, and you will calculate arc length symbolically (using SymPy) and numerically (using NumPy).

Plotting Parametric curves with SymPy#

The basic syntax for plotting a parametric curve in SymPy is plot_parametric((expr_x,expr_y),range), where expr_x is an expression that defines \(x\) in terms of our parametric (most likely t), expr_y is an expression that defines \(y\) in terms of the parameter, and range defines the domain for the parameter, using the same syntax as for integrals. For example, for \(t\in [1,3]\) we would use (t,1,3) for the range.

You can plot more than one curve on the same set of axes by including an ordered list of curves: for two curves, you would have something like plot_parametric((expr_x1,expr_y1),(expr_x2,expr_y2),range) if the range is the same, or plot_parametric((expr_x1,expr_y1,range1),(expr_x2,expr_y2,range2)) for different ranges.

Optional arguments include line_color for the colour of the curve, label, xlabel, and ylabel to label the plot, \(x\) axis, and \(y\) axis, respectively, and xlim, ylim to set the bounds for the \(x\) and \(y\) axes (equal to an ordered pair).

Here is an example, which plots the ellipse with parametric equations \(x=4\cos(t), y=3\sin(t)\), for \(t\in [0,2\pi]\).

import sympy as sy
sy.init_printing()
t = sy.symbols('t')
sy.plot_parametric((4*sy.cos(t),3*sy.sin(t)),(t,0,2*sy.pi))

You can also plot more than one curve on the same axes: just include multiple ordered pairs. For two curves with the same parameter domain, the syntax looks like

sy.plot_parametric((f1(t),g1(t)),(f2(t),g2(t)),(t,a,b))

For example, the following will plot the curves \(x=t,y=\cos(t)\) (cosine curve) and \(x=t, y=\sin(t)\) (sine curve), for \(t\in [-2\pi,2\pi]\):

sy.plot_parametric((t,sy.cos(t)),(t,sy.sin(t)),(t,-2*sy.pi,2*sy.pi))

One catch: if you wanted to specify a different colour, you can’t do this all in one go, because the colour gets applied to both curves.

sy.plot_parametric((t,sy.cos(t)),(t,sy.sin(t)),(t,-2*sy.pi,2*sy.pi),line_color='red')

But we can use the following to override the colour for one of the curves:

p=sy.plot_parametric((t,sy.cos(t)),(t,sy.sin(t)),(t,-2*sy.pi,2*sy.pi),line_color='red',show=False)
p[0].line_color='blue'
p.show()

Problem 1#

Plot the following parametric curves. (You probably want to plot each on its own set of axes.)

If you don’t want to type out sy.plot_parametric every time, you could add a line like pp=sy.plot_parametric.

(a) \(x=t^3-2t, y=t^2-t, t\in [-1,2]\)

(b) \(x=t+\sin(2t), y=t+\sin(3t), t\in [-2\pi, 2\pi]\)

(c) \(x=\sin(3t), y=\sin(4t), t\in [0,2\pi]\)

Plotting parametric curves with GeoGebra#

Sometimes you want something a little simpler to use than a Jupyter notebook. Fortunately, there are some great free software programs out there, such as Desmos, and GeoGebra. GeoGebra can do derivatives, integrals, geometry, statistics, and more. And the interface involves a little more pointing and clicking, if you like that sort of thing.

We will use GeoGebra classic. Choose graphing mode to create your plot.

You can create plots using the input box, which is next to the \(+\) sign at the top-left.

The syntax for a parametric curve is: Curve(Expression,Expression,Parameter Variable,Start value,End value). For example, you could plot the unit circle using Curve(cos(t),sin(t),t,0,2*pi).

Problem 2#

Use GeoGebra to plot the curve \(x=\cos(t+\cos(2t)),y=\sin(t+\sin(4t)), t\in[0,2\pi]\).

When you are happy with your plot, click on the menu button in the top-right corner, and choose Export Image.

Then, double-click the markdown cell below, and add your image. You should be able to just copy it to the clipboard, and then use Ctrl-V to paste the image into the cell.

Or, to play it safe, download the image from GeoGebra, upload it to Jupyter in the same folder as this notebook, and include it using the syntax ![my amazing image](myimage.png), assuming that you saved the file as myimage.png.

Double-click this text to add your image, and hit Ctrl-Enter when you’re done.

Problem 3#

Use parametric curves to generate an emoji of your choice.

Note: you will need more than one curve. Unless you are feeling ambitious, I recommend sticking to the classic smiley face.

Arc length for parametric curves#

The formula for arc length for parametric curves is a fairly straightforward extension of the one we learned earlier. For a graph \(y=f(x)\), we started with \(\Delta s = \sqrt{\Delta x^2+\Delta y^2}\) and factored out the \(\Delta x\) to get \(\Delta s = \sqrt{1+\left(\frac{\Delta y}{\Delta x}\right)^2}\Delta x\). Taking the limit gave us \(ds = \sqrt{1+f'(x)^2}dx\).

Now, given \(x(t)\) and \(y(t)\), we have \(dx = x'(t)\,dt\) and \(dy = y'(t)\,dt\). The same sort of argument gives us

\[ds = \sqrt{x'(t)^2+y'(t)^2}\,dt.\]

Problem 4#

For the curve given by \(x=\dfrac{t}{1+t}, y=\ln(1+t), t\in [0,2]\):

(a) Set up the integral using SymPy, and display the integral. (To display an integral without evaluating it, use Integral instead of integrate.) You will need to define the expressions for \(x\) and \(y\) and compute their derivatives before setting up the integral.

(b) Evaluate the integral using SymPy.

Note: if SymPy fails to evaluate the integral, try using the change of variables \(u=t+1\), and see if it succeeds with the resulting integral. Don’t forget to adjust the bounds!

Problem 5#

The equations $\(\begin{aligned}x&=11\cos(t)-4\cos(11t/2)\\y&=11\sin(t)-4\sin(11t/2)\end{aligned}\)$ define a curve called the epitrochoid.

(a) Plot the curve using SymPy, and experiment to determine what interval gives the complete length of the curve.

(b) Approximate the length of the curve using Simpson’s Rule with 50 subintervals.