Here’s a quick introduction to plotting with Mathematica:
Basic plotting
The basic plot command takes the form
Plot[function of variable,{variable,starting value,ending value}]
For example, the input Plot[Sin[t],{t,0,2Pi}]
should yield the following plot
We can change the vertical and horizontal range of the plot using the following:
Plot[Sin[t], {t, -Pi, 2 Pi}, PlotRange -> {-2, 3}]
We can add labels to the axes:
Plot[Sin[t], {t, -Pi, 2 Pi}, PlotRange -> {-2, 3}, AxesLabel -> {t, Sin[t]}]
Finally, we can plot multiple functions at once:
Plot[Sin[t], {t, -Pi, 2 Pi}, PlotRange -> {-2, 3}, AxesLabel -> {t, Sin[t]}]
Plotting discrete points and Riemann sums
Mathematica can be used to plot discrete points along a function. For example:
DiscretePlot[Sin[x], {x,0,2Pi,Pi/12}]
What does the syntax {x,0,2Pi,Pi/12}
mean?
If we are interested in Riemann sums, it can be helpful to shade little rectangles based on the points plotted. For left endpoints we use the command:
DiscretePlot[Sin[x],{x,0,2Pi,Pi/12},ExtentSize->Right,PlotMarkers->"Point"]
WARNINGS:
- Mathematica uses the command Right to indicate that the rectangle is on the right side of the plotted point, even though this is the left endpoint we are using for the height.
- Furthermore, we may or may not want the first/last point to be part of our Riemann sum. Remember that the left endpoint method does not use the last
-value. Thus we should really stop at
. The code for this is
DiscretePlot[Sin[x],{x,0,2Pi-Pi/12,Pi/12},
ExtentSize->Right,
PlotMarkers->"Point"] - Note also: sometimes Mathematica puts the axes in a funny place. You can control the point where the axes cross by including the option
AxesOrigin -> {1, 2}
, which puts the cross-hairs at the point.