In this section we give you examples of how you can use Mathematica for some familiar and elementary operations.

Opening a workspace and executing a Mathematica command

In the first example, we illustrate some of the algebraic and graphical capabilities of Mathematica. First first you must "open" a line to type in as follows:

• If not at the top of a "clean" notebook window, move the cursor slowly down the window until the cursor becomes a horizontal I-beam.
• Click the mouse; a grey line will appear across the window.

You can now enter new text in the notebook window. The first example defines y, as a function of x. Type the following exactly as it is written:

y = x^3 - x^2 - 9 x + 9

The line you've just typed is called a command, or "input". When you "enter" such an input, Mathematica processes it and returns "output" (or a result). To obtain the result you must first "execute" the command by following these steps:

• If not already there, move the cursor to the end of the command; in this case, after the second 9. (Alternatively, put the cursor on the ] to the far right of the command),
• Click the mouse to select the command,
• Hit the Enter key, located on the extreme lower right of the keyboard. (Note: this is NOT the same as the (carriage) Return key that you have been using.)

Once the command is completed, you will see an input line labeled In[1] that contains the original command, and an output line labeled Out[1]. Notice that the result in the output line is written differently than the way we typed it; Mathematica prefers to write polynomials in increasing powers of x.

Writing a Mathematica command

The input line above is an example of writing the definition of y as a cubic polynomial in x. There are two items you should notice in the above command that are peculiar to the Mathematica program:

• "x cube"and "x square" are typed using the carat (^ ) .
• The product "9 x" does not need a multiplication symbol. The two possible forms for writing a product are "9 x" (employing a space as above) and "9*x" (employing an asterisk).

Plotting a function

The command below is a very common plotting format that will soon become familiar to you. (Note: this plot command assumes the above definition of y; if you have not executed a command defining y, scroll back and do it now.) Open a new line in the notebook window and type the following command exactly as written.

Plot[y, {x,-7,7}, PlotRange -> All]

There are some items to note in this plot command that are peculiar to Mathematica:

• Notice the square brackets, [ and ], around the arguments of the Plot command. Also note {x,-7,7} specifies a domain interval for x. It is important to remember when to use the different types of brackets. Mathematica is very sensitive to different bracket styles.
• "PlotRange -> All" is a plotting option, telling Mathematica that---"yes, we do want to see the entire graph". (Other plotting options will be introduced as we need them.) The arrow (->) is created with the "hyphen" followed by the "greater than" keys on the keyboard.
• Notice the upper case letters in Plot and PlotRange. This is typical of all Mathematica commands and options, so you will need to get used to this! In contrast, if YOU define a new function, like y above, you are free in the use of upper and lower case letters.

Execute the plot command below to see what the graph of y looks like. (Select the command by locating the cursor after it, and hit Enter). You can see that the graph depicts the essential character of function y.

Modifying a command

You can now practice modifying a Mathematica command and, at the same time, get a closer look at the graph.

Follow these steps to change the domain interval for x in the plot command below:

• Carefully place the cursor in front of the -7;
• Press and drag the mouse across the -7,7 (it will be shaded grey);
• Type -4,4 (the -7,7 will be replaced).

Now execute the modified plot command. (If the command does not execute, it's always a good idea to check for typographical errors. If there are no errors and the graph still does not plot, ask for help.)

You will now see a more detailed graph of y near a point where it crosses the x-axis.

Factoring polynomials

In the above graph it looks to the eye as if the function y is equal to 0 somewhere around x = -3, x = 1, and x = ?. That is, it appears that y has roots at x = -3, x = 1, and x = 3.

• Locating roots is an important problem that we will pursue from several directions this semester. But in this case, the question is easily answered because Mathematica is good at factoring polynomials.

To see this, open a new command line and execute the following command.

Factor[y]

It is now clear that y = 0 precisely at x=-3, x=1, and x=3.

Zooming in on a graph

Let's return to the graph of y in order to discuss an issue that will be very important throughout our study of calculus.

Again, execute:

Plot[y, {x,-4,4}, PlotRange -> All]

A recurring theme in calculus can be paraphrased: most functions are "almost linear" if you look closely enough. To illustrate this point, you can "zoom in" on the graph at x near 2:

• Modify the plot command below so that the domain interval is 1.9 to 2.1. (If necessary, you may scroll back to review the directions Modifying a command.)
• Execute the plot command.
You should see a smaller portion of the graph and note that it is starting to straighten out a bit. To further illustrate the point, modify the domain interval in the plot command to 1.99 to 2.01 and execute the command. Notice that the graph is almost linear on this restricted domain interval.

Is there anything special about the point (2, -5)? No. You may want to experiment on your own by modifying the command with any value for the domain of x that you choose, and "zoom in" as we have done. Remember the fundamental point being made:

most functions are "almost linear" if you look closely enough.

We will revisit this fundamental notion often in Calculus.

http://math.colgate.edu/mathlab/basicelts.html
Revised: March 1, 1996.
Questions to: valente@colgate.edu