5. Visualizing functions

Here we will discuss visualizing functions, rather than data (which is covered in Section 9). We will discuss what programs can do this, and then take a tour of some examples and what insight we get from those examples.

We will have two goals, beyond getting comfortable with plotting software: (a) learning how functions appear visually, and (b) looking at how the intersection of equations gives a lower dimensional space, and what that space looks like.

5.1. Command-line and web

We can either plot on the command line, or use a web-based plotting system.

On the command line I recommend gnuplot for “quickies”: it allows simple plotting of functions. On Linux systems it is already there for ready package installation; on other operating systems one will have to download it, or use a third party packaging approach (such as homebrew) to install it.

On the web there are two widely used system: GeoGebra and Desmos. Both work well for simple line plots, but at this time (2022-12-12) only GeoGebra offers surface plots. GeoGebra is also based on Free/Open-Source software, making it an excellent choice overall.

For the first few examples we will give both the instruction in gnuplot and the GeoGebra instruction, and after a while we will switch to simply showing the gnuplot instructions.

Overall I recommend getting used to command line programs rather than web sites, since such approaches can be scripted and are reproducible.

5.2. Reduction in dimension: line plots

Remember that we are always looking at the reduction in dimension that functions bring, so let us start by plotting some simple functions.

$ gnuplot
# then at the gnuplot prompt:
plot x**2
replot -2*x + 3

In GeoGebra at https://www.geogebra.org/calculator you can type in the two equations:

f(x) = x^2
g(x) = -2 x + 5

after which you will have to zoom out a bit and shift the graph down to find all the points at which the line and the parabola intersect.

Exercise

in both approaches, learn to zoom in and out. Then, zooming in, find the \((x, y)\) values of the two points at which the line and parabola intersect. Compare them to what you would get with the quadratic formula.

Finally: notice how we start with the plane (all \((x, y)\) points), which has dimension 2. The first equation reduces the \((x, y)\) pairs to just those on the parabola, which has dimension 1. Finally the second equation brings it down to just two points, each of which has dimension zero.

5.3. Reduction in dimension: surface plots

$ gnuplot
# then at the gnuplot prompt:
reset
set zrange [-2:32]
set pm3d
set samples 150
set isosamples 60
set hidden3d
splot 30*exp(-(x**2 + y**2) / 10)
replot x + y
replot 2

In GeoGebra at https://www.geogebra.org/calculator you can type in the two equations:

z = 30 e^(-(x^2+y^2)/10)
z = x + y
z = 10

Then zoom out to see the whole figure.