Simple 2D Graphs

Producing a two-dimensional graph in Mathematica is quite easy. To do this you must
give Mathematica:

(1) A symbolic expression containing at most one variable.

(2) The variable that is contained within the expression. The horizontal axis
of the graph will correspond to values of this variable; the vertical axis will
correspond to values of the expression.

(3) The two endpoints of the horizontal axis.

For example, the Mathematica command

Plot[2*x^3 - 3*x^2 + 1, {x, 0, 1}];

will plot the value of 2*x^3 - 3*x^2 + 1 as x ranges from 0 to 1.

Multiple Graphs

You can graph more than one function on the same plot. Both must be functions
of the same variable. For example, to graph the function from the last section
along with sin(x) on the same plot:

Plot[{2*x^3 - 3*x^2 + 1, Sin[x]}, {x, 0, 1}]; 

Notice that we simply enclose the two expressions to be graphed inside curly
braces and separate them with commas. Mathematica doesn't label the two curves, so
you have to exercise some care in telling them apart.

Command-Click the mouse inside the plot window. You will see that the horizontal and
vertical coordinates of the mouse point are displayed in a field at the top or bottom of the notebook window (exactly where depends on which version of Mathematica you have).
This is useful, for example, if you want a rough idea of where two curves
intersect. Where do the two curves that you've just plotted intersect?

Click here for the answer

What Can Go Wrong?

It is easy to make mistakes when asking Mathematica to produce a plot, and
unfortunately Mathematica does not always tell you what's gone wrong. Let's look at
a few examples so you'll know what to expect.

All functions that you plot must be functions of a single variable. Mathematica will
give you an error message if you violate this restriction. For example, try
plotting x*y and see what happens.

Mathematica will only plot a function at the points at which it is real-valued. Try
plotting Sqrt[x] as x ranges from -5 to 5. What happens?

Click here for the answer

This sensible behavior can be confusing in a couple of contexts. To see what
we mean, try plotting x*I as x ranges from 0 to 10. What happens?

Click here for the answer

Now try plotting z(x) as x ranges from 0 to 10. Can you explain
what happens?

Click here for the answer