Note: Thoughts expressed in this article are solely those of the author(s). Any advice given in this article may not work in all situations.
If you need to see Part 1 of this article, you can access it here.
Showing your students how to graph trigonometric functions, using different techniques, can be fun. Besides using softwares, you can show your students how to program a computer to graph trigonometric functions.
Programming a computer to graph trigonometric functions
Again, we think that it’s best to show your students how to graph trigonometric functions by hand before showing them how to use automated tools, and one reason is that computer codes may have bugs thus potentially making mistakes graphing the functions.
One advantage of showing them how to program a computer to graph trigonometric functions is that they don’t need to constantly rely on the web for graphing. Once they download the programming language and associated packages to their computers, they can graph functions without accessing the web.
If you choose to use programming, check to see if your students know how to use a computer. Also, it may be best if each student has access to a computer.
Selecting a programming language and libraries
There probably are many programming languages and many libraries that you can find on the web to graph trigonometric functions. You may need to read upon some of them to see which one your students can use with ease. Some programming languages may require more prerequisite knowledge than others.
Python has a module to compute values of trigonometric functions. To access the module, you need to use the code ‘import math‘. The trigonometric functions in the module accept angles in radians.
However, to graph trigonometric functions, that module is insufficient. You’ll need to download external libraries.
Python libray: Matplotlib
Matplotlib is a library that you can use to make plotting in 2 dimensions. It outputs its graphs in a separate window and allows you to zoom the graph for better viewing. You can find information about how to download it here. To use it, you need only use the code ‘import matplotlib.pyplot as plt‘.
Python library: Numpy
To graph functions with Matplotlib, you’ll need to create two arrays, one with the independent variables and the other with the dependent variables. Numpy is a library you can use to create these arrays. You can go here for information about how to install it. To use it, you need only use the code ‘import numpy as np‘.
It’s time for graphing!
Once your students have the appropriate programming language and the associated libraries, you can show them the codes to use to graph couple functions. If you teach at a school, there may be a computer lab with computers that already have the softwares you need. You probably need to graph couple ones first; then encourage them to graph couple more on their own or in small groups.
In the case of Python, here’s what the codes look like:
The function np.arange() divides an interval into subintervals of a specified length. In our case, it divides the interval from \(0\) to \(8 \pi\) into subintervals of length \(0.1\).
The function plt.plot(x,y) plots the points whose coordinates come from the two arrays that are inputted.
Finally, plt.show() unsurprisingly shows the graph.
Here’s how our graph looks like:
With these libraries, you can graph more complicated trigonometric functions; for instance, here’s the graph of \(y = 3 \sin (x + \pi) + 2 \):
And the codes for that graph are:
Let’s show you one more: here’s the graph of \(y = \tan(x)\):
And here are the codes:
If you ever have a graph similar to the last graph, you may need to explain to your students that the computer doesn’t know how to handle the infinity, so an approximation is the best you can get.
Questions about the computer-generated graphs
After each function your students graph with the computer, you may encourage them to pause and to ask if that graph is really the graph of the function since, as we’ve brought up before, the graphing softwares may have bugs, so it may be safe to verify that the computer’s results are correct. Some questions you may encourage them to ask are: Is the amplitude of the computer graph the same as that of the function? Is the shift the same? Is the period the same? Are the intercepts the same?