Mathematica: Plotting functions

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

BasicSinePlot

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 x-value. Thus we should really stop at x=2\pi -\frac{\pi}{12} . The code for this isDiscretePlot[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 (1, 2).
Advertisements
This entry was posted in Mathematica. Bookmark the permalink.

Leave a comment here

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s