Introduction to Mathematica for High School Math (for Students and Teachers) #5
Author
Ruth Dover
Title
Introduction to Mathematica for High School Math (for Students and Teachers) #5
Description
Introduction to Mathematica for High School Math
Category
Educational Materials
Keywords
Mathematics, education
URL
http://www.notebookarchive.org/2021-09-6h22zw6/
DOI
https://notebookarchive.org/2021-09-6h22zw6
Date Added
2021-09-14
Date Last Modified
2021-09-14
File Size
44.2 kilobytes
Supplements
Rights
Redistribution rights reserved



Tutorial 5: Plotting
Tutorial 5: Plotting
R. Dover, IMSA
Basic Graphs
Basic Graphs
Graphics in Mathematica® are amazing! This tutorial will help you get started.
The code following is for the graph of for (again, note the space between and to denote multiplication. Otherwise, this would be read as one variable, , with a four-letter name):
f(x)=xsin(2x)
−1≤x≤5
x
Sin[2x]
xSin
Plot[xSin[2x],{x,-1,5}]
The range is chosen automatically to show the most important features of the graph, but this may be controlled by the user, along with many other options. Several examples are given. Look at each one carefully. The function is given first, followed by the curly braces with the domain. After that, options may be given in any order. There are lots of arrows, braces, capitals and commas to watch. Understanding the system will make it much easier to include a variety of options:
Plot[xSin[2x],{x,-1,5},PlotRange5]
Plot[xSin[2x],{x,-1,5},PlotRange{-3,8}]
Plot[xSin[2x],{x,-1,5},PlotStyleRed]
Dashed
Thick
Plot[xSin[2x],{x,-1,5},PlotStyle{Dashed,Thick}]
Plot[xSin[2x],{x,-1,5},PlotStyle{Dashing[{.05}],Thickness[.03]}]
Plot[xSin[2x],{x,-1,5},AspectRatioAutomatic,Ticks{{π/2,π,3π/2},Automatic}]
Plot[xSin[2x],{x,-1,5},PlotLabel"ƒ(x) = x sin(2x)"]
Create one of your own graphs. Then make several changes. Experiment a little.
Help!
Help!
Clearly, there are lots of commands and options in the Wolfram Language™. And clearly, it is impossible to remember all of them. Fortunately, Mathematica provides a lot of help. You may have already seen or tried this, but in a new cell, start to type “Plot” by typing just “Pl”. Pause. Two letters will allow you to see all commands that begin with these letters. Clicking the box with two downward arrows will show more commands.
Now, choose from the list. Click the two downward arrows again. This time, you will see the basic syntax. Choose the first function (for one graph), and the template will appear. Nice!
Plot
This can obviously be quite helpful. Try typing just the first two letters of a few other commands.
But what about available options?
Options[Plot]
Whoa! Read through that list carefully. In each case, the default value for each option is shown.
More Graphs
More Graphs
To graph two or more functions on one graph, create a list of functions:
Plot[{xSin[2x],-3x+1},{x,-4,4}]
3
x
Note that by default, Mathematica shows the graphs in two different, muted colors. Sometimes, this is fine, but you may also want to control more:
Plot[{xSin[2x],-3x+1},{x,-4,4},PlotStyle{Red,Blue}]
3
x
To add more styles to each graph, we need a list of lists:
Plot[{xSin[2x],-3x+1},{x,-4,4},PlotStyle{{Red,Thick},{Blue,Dashed,Thick}}]
3
x
As stated before, you may control the thickness and the size of the dashes. But sometimes, simply writing and is good enough!
Thick
Dashed
Plot[{xSin[2x],-3x+1},{x,-4,4},PlotStyle{{Red,Thickness[.003]},{Blue,Dashing[{.05,.02}],Thickness[.01]}}]
3
x
Colors
Colors
Some colors such as and have been used, and the Wolfram Language™ understands these and others. (To see what Mathematica knows, from the Palettes menu, choose ColorSchemes. Under the section Named, look at the colors under System.)
Red
Blue
Colors may be chosen in other ways. RGB stands for Red, Green, Blue and requires three numbers all from 0 to 1, inclusive. Try some different numbers:
Plot[xCos[2x],{x,0,2π},PlotStyle{Thick,RGBColor[1,0,0]}]
Another option is to use , where is a number between 0 and 1. Try other values of , remembering your rainbow:
Hue[k]
k
k
Plot[xCos[2x],{x,0,2π},PlotStyle{Thick,Hue[0]}]
Check out more possibilities in the palette if you wish.
Asymptotes
Asymptotes
Look at the basic following. In recent versions, the Wolfram Language has figured out how to avoid showing the vertical asymptotes that many other programs show:
Plot
In[]:=
g[x_]:=
1
(x-2)(x+1)
In[]:=
Plot[g[x],{x,-3,4}]
If you like asymptotes and want to see something a little more complicated, check this out:
In[]:=
Plot[g[x],{x,-3,4},Epilog{{Thick,Red,Dashed,InfiniteLine[{{-1,0},{-1,1}}]},{Thick,Red,Dashed,InfiniteLine[{{2,0},{2,1}}]}}]
The command draws a line through two given points to the edges of the window.
InfiniteLine
Two More Options (Optional)
Two More Options (Optional)
Mesh
Mesh
Now look at a basic graph with the option :
Mesh
Plot[Sin[x],{x,0,2π},MeshAll]
What is this doing? It is showing you all of the points that it is plotting to make the graph. The remainder of the graph is created by joining these points together with straight line segments. Note that calculators use equally spaced points in all cases, while Mathematica cleverly puts in more points where the function is more curvy.
Mesh may be used to do a number of other things. This next example gives 12 evenly spaced points within the domain:
Plot[Sin[x],{x,0,2π},Mesh12,MeshStylePointSize[Large]]
For points spaced evenly within the range, use a "pure" function, shown at the end:
Plot[,{x,0,2π},Mesh8,MeshStyle{Red,PointSize[Medium]},MeshFunctions{#2&}]
x
RegionFunction
RegionFunction
This option will allow you to plot certain parts of your function, subject to your restrictions:
Plot[Sin[x],{x,0,2π},RegionFunctionFunction[{x,y},Abs[y]>.3]]
Plot[Sin[x],{x,0,2π},RegionFunctionFunction[{x,y},.3<Abs[y]<.8]]
Palettes (Again)
Palettes (Again)
In the palette, under Basic Commands, find the button 2D. Look around a little. And again, we will come back to some of these other graphs in more detail later. For right now, choose Plot. Fill in a function of your choice, along with the variable, min and max values. Now choose a few of the options and fill in appropriate items. Note the color palette a little further down. Just click a color when needed.
By Options, it says Automatic Positioning. Be sure you noticed what this implies. (It is very nice!)
Exercise
Exercise
Let and . Define both of these functions. Then plot them together, adding some colors and thickness or dashing to each graph. Put a frame around the plot and label it Approximations.
f(x)=cos(x)
g(x)=1−/2
2
x
Be sure to clear and when you are done.
f
g


Cite this as: Ruth Dover, "Introduction to Mathematica for High School Math (for Students and Teachers) #5" from the Notebook Archive (2021), https://notebookarchive.org/2021-09-6h22zw6

Download

