Plotting with Mathematica

Plot

Plot is a simple two-dimensional plotting function in Mathematica. Plot takes two arguments when it is called and these two arguments can contain numerous parts. This may not sound so simple, but once you see how it works it is very straight forward.

The first argument to Plot is the function or functions to be plotted. The second argument is a list containing a variable to be used a the range over which the variable is to be plotted.

Example:

Plot[Cos[x], {x, -2Pi, 2Pi}]

The line shown above will plot a simple cosine curve from -2pi to 2pi. The function, Cos[x], is the first argument to Plot. This is then followed by a comma and the second argument. Brackets are used with the second argument because it contains a few parts, each of which are separated by a comma. The first part is the variable to be used followed by the start of the range, and then the end of the range.

The important points to remember about Plot is that it is passed two arguments separated by a comma. The arguments themselves can contain numerous parts which would then be enclosed in brackets and each separated by a comma.

Numerous functions can be plotted at the same time with one call to Plot. These functions must use the same variable and the same range though.

Example

Plot[{Sin[x], Cos[x]}, {x, -2Pi, 2Pi}]

This line will plot a sine and cosine function from -2pi to 2pi. Notice the both Sin[x] and Cos[x] are enclosed by brackets and separated by a comma.

Plot3D

Plot3D works in the same way that Plot does except two variables are used and the function is called with a minimum of three arguments. These arguments consist of the function or functions to be plotted, a variable and its range, and a second variable and its range. Again these arguments are separated by commas.

Example

Plot3D[Sin[x]+Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}]

This equation will plot a mountainous surface that resembles an egg carton. Both of the axises will have a range from to 4pi.

Plot3D is able to accept more then three arguments. These arguments generally handle the appearance of the final plot of the describe surface and the way in which it is viewed.

More Plot3D Examples

Plot3D[Sin[x+Sin[y]], {x, 0, 4Pi}, {y, 0, 4Pi}, PlotPoints->30]

Plot3D[Sin[x+Sin[y]], {x, 0, 4Pi}, {y, 0, 4Pi}, PlotPoints->50, Mesh->False]

The lines above describe a 3 dimensional plot that has been adjusted slightly for viewing purposes. In the first line PlotPoints->30 increases the number of divisions in the plot. By increasing the number of divisions or PlotPoints, as was done in the second example, a surface will essentially become more smooth. The second line contains the argument ,kbr> which has the effect of removing the grid lines on the surface.

Summary

The example shown above have been taken from Exploring Mathematics with Mathematica and have been intended to give a basic beginning to plotting with Mathematica. The references contain some books that are recommended for people who wish to learn the more advanced features of Mathematica.

References

[ST94] Applied Mathematica
William T. Shaw and Jason Tigg
Addison-Wesley, Menlo Park CA (1994).

[Rob95] Engineering Mathematics with Mathematica
John S. Robertson
McGraw-Hill, New York NY (1995).

[GG91] Exploring Mathematics with Mathematica
Theodore W. Gray and Jerry Glynn
Addison-Wesley, Menlo Park CA (1991).

Week 1 Precept

Assignments

Last Modified: 97.08.12 Michael Carreno <mcarreno@cs.princeton.edu>