11.3: Other Function Plots
( \newcommand{\kernel}{\mathrm{null}\,}\)
Here's some preliminary commands to run if they haven't been yet.
Parametric Plots
Recall that a parametric curve is a set of points in the xy-plane given by (x(t),y(t) for functions x(t) and y(t). The variable t is called the parameter. A classic example is the circle that can be written as
x(t) = \cos t, \qquad y(t) = \sin t \nonumber
To plot the circle using this form, enter
and note that the legend is turned off, since with one curve, it doesn’t make much sense. Notice that this should be a circle, but it looks like an ellipse due to the aspect ratio. If one instead adds the aspect_ratio=:equal
option, as in
Exercise
Produce a plot of the curve x(t) = t^3-t, y(t)=t^2 for -2 \leq t \leq 2.
Implicit Curves
An implicit curve is the set of points such that f (x, y) = 0 (or any constant) and a circle is the classic example. For example, x^2+y^2=1. Although there are others ways of doing this, we will use some algebra to write the circle as f(x,y) = x^2+y^2-1 .
We can plot this with the contour
function for example
Note that again, we have used the option aspect_ratio = :equal
to ensure that the circle looks like a circle. The resulting plot is exactly the same as the circle above.
The following example is a bit more visually interesting. This is the function f(x,y) = sin(x+y)-cos(xy)+1
Exercise
A cardiod is a 2D curve that looks a bit like a heart. It can be represented by an implicit curve with the equation
(x^2+y^2)^2 +4ax(x^2+y^2) -4a^2y^2 = 0 \nonumber
Plot the cardiod with a=1 using the code block below
Surface Plots
If we have a function of 2 variables, a surface plot is nice to use. For example, if we have the function
f(x,y) = e^{-0.1(x^2+y^2)} \label{3dbell}
and we want to plot it from -3 to 3 in both directions, if we define
and then plot with
Exercise
Produce a surface plot of the function f(x,y)=\sin x \cos y for 0\leq x \leq 2\pi, 0\leq y \leq 2\pi using the code block below
Heat Maps
A heat map is a 2-dimensional version of a surface plot in which the height of each value is given a color. The following produces a heat map of the function in \ref{3dbell}
Exercise
Produce a surface plot of the function f(x,y)=\sin x \cos y for 0\leq x \leq 2\pi, 0\leq y \leq 2\pi using the code block below