Before you can read through this notebook, you need to know several things about "getting around" inside the notebook window. This section shows you how to use the mouse to `scroll', and how to select, change and delete text.
The mouse is the small rectangular box that is attached to the keyboard. By sliding the mouse on a smooth surface (such as a pad), you can control the movement of the cursor on the screen. You move the cursor to point to items you want to manipulate. There are two "buttons" on the mouse, either of which will (unless altered) work for your purposes.
There is a faster way to move up and down. Inside the grey margin strip at the left of the window is a short vertical bar with a small circle in the center (the scroll bar). You can use this bar to scroll quickly down, or up, the page:
1. Point the cursor on the scroll bar,
2. Press the button (hold it down), and
3. Drag the scroll bar down or up to correctly position the text.
You will notice that the cursor changes shape as it moves about the screen. If you move the cursor from a position inside this window to a border of the page, or off the page, the cursor will change from a vertical I-beam shape to an arrow. Or, if you slowly move down the page the cursor will occasionally change, briefly, to a horizontal I-beam shape. (This occurs between "cells"s, where a cell is a block of text defined by the bracket, ] , to the right---e.g. see the ] for this paragraph). Move the cursor around and see it change.
Below you will see seven section titles which serve as a `table of contents' for the rest of this tutorial. These sections are "closed up" for convenience in finding the section of interest. For example, if you needed to get off the computer now, you would want to "open up" the sections "How to exit this tutorial" and "Logging off the NeXT". But, let's assume that you want to open the next section, "What is Mathematica?" To do this:
1. Put the cursor on the small rectangle to the right of the section title;
2. "double-click"---that is, make two short clicks of the mouse.
This (short) section should open up for you. Try it.
If you want to close up that section, double-click on the ] to the right, enclosing the entire section, including the title. Try it.
Notice the next section, "Some basic elements of Mathematica", has a larger rectangle following it; this is because it is a much larger section.
Open this section up when you are ready to start learning Mathematica.
The last section, "Some Mathematica commands", is a summary of the commands that you will be using this year; and is for later reference.
Mathematica is a state-of-the-art and remarkably powerful system for doing mathematics by computer. One can use Mathematica in many different ways, but in your calculus courses you will use only a small portion of its capabilities. (You will use more advanced features in your later course work and, very likely, in your professional career). The following tutorial sections will show you how to use to do numerical, symbolic and graphical calculations. You will get a sense of the graphical power in this tutorial.
One of the remarkable features of Mathematica is its `symbolic' capabiltity; i.e. it ability to very quickly do messy algrebraic computations and simplifications. Such packages can thus save us many tedious hours of (error-prone) work. Similarly, you will see later this term that Mathematica is also very good at calculus operations (differentiation and integration).
These time saving features will not take all the work out of a calculus course, rather it will allows us to probe more deeply into central issues of the subject.
In the first example, we illustrate some of the algebraic and graphical capabilities of Mathematica. Here is an example of an expression that defines y, a function of x:
The above line 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:
1. Move the cursor to the end of the command; in this case, after the
second 9.
(Alternatively, put the cursor on the ] to the right of the command),
2. Click the mouse to select the command,
3. Hit the Enter key, located on the extreme lower right of the keyboard.
(Note: this is NOT the same as the Return key that you have been
using.)
The above command is repeated below. Follow the directions above to execute it now. There will be a short delay while Mathematica performs the command. 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.
The input line above is an example of writing the definition of y as the 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 (^ ) .
• product "9 x" does not need a multiplication symbol. Two possible
forms are: with a space as in "9 x" or with an asterisk as in "9*x".
For practice, after opening a line, type the same Mathematica command that we worked with above, and execute the command. (Remember: to execute a command, first `select' it by clicking behind the command, and then hit the Enter key.)
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.)
:[font = input; preserveAspect; ]
Plot[y, {x,-7,7}, PlotRange -> All]
:[font = text; inactive; preserveAspect; ]
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 the domain of x. It is
important to remember when to use the different types of brackets.
Mathematica is very `narrow minded' about this.
• "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 functions and options; so get used to this! In contrast,
if YOU define a new function, like y above, you are free in the use of
Follow these steps to change the domain of 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.)
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 = 3. How to find where y=0 is an important question 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, execute the following command.
Let's return to the graph of y and get into an issue that will be very important throughout our study of calculus. Again, execute:
:[font = input; preserveAspect; ]
Plot[y, {x,-4,4}, PlotRange -> All]
:[font = text; inactive; preserveAspect; ]
A recuring 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:
1. Modify the plot command below so that the domain of x is 1.9 to 2.1.
(If necessary, you may scroll back to review the directions "Modifying
a command.")
2. Execute the plot command.
:[font = text; inactive; preserveAspect; ]
You should see a smaller section of the graph and note that it is starting to straighten out a bit. To further illustrate the point, modify the x domain in the plot command below to 1.99 to 2.01 and execute the command, and notice that the graph is almost linear.
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".
Below we point out a few more characteristics in some Mathematica commands that you will use during the year. Execute each command, notice its output, and read the explanation that follows.
In this Expand command, the percent sign (%) stands for `the last result'. Therefore, the product x y is expanded here to get a fourth degree polynomial.
:[font = input; preserveAspect; ]
Factor[%]
:[font = text; inactive; preserveAspect; ]
Likewise, this factors the last result. Finally, a bit more subtle command:
:[font = input; preserveAspect; ]
y /. x -> 2
:[font = text; inactive; preserveAspect; ]
The effect of this command is to evaluate y at x=2. It illustrates a very important feature of Mathematica. You should read this command as "evaluate y subject to the rule: (x is set to 2)". The operator /. is made up by a slash / followed by a period (.); and the arrow is a "hyphen" followed by a "greater than" sign. The spaces after the y, before the x and before the 2 are NOT necessary here, but they help in the readability of the command.
As you probably noticed, the last example is an awkward way to evaluate y at x = 2. An easier way to do such evaluations it is to use the "function" notation. The following is an example of a function definition for f :
Some advantages of the function notation are shown in the examples below. These examples give you an idea of the power you have in Mathematica when f is defined as an actual function. The original argument, x, can be replaced by any numerical value or symbol. EXECUTE the following commands, one at a time, starting with the definition of f .
As you can see, the original argument, x, can be replaced by ANYTHING! For example, with the argument t^3 + 1 we obtained a sixth degree polynomial (the `composition' of the functions x^2 + 5 and t^3 + 1).
You can form a so-called "rational function" by taking the quotient of y and f[x]. Execute the following command to define the ratio of y and f[x], and then execute the second command to plot the function.
:[font = input; preserveAspect; ]
r = y/f[x]
:[font = input; preserveAspect; ]
Plot[r, {x, -20, 20}, PlotRange -> All]
:[font = text; inactive; preserveAspect; ]
You can see here that r has the same general shape, for "small" x, as did y. (Why is this?) Also notice that for "large x" the graph of r looks linear. (Why is this?) To explore the second question graphically we plot functions r and x-1 on the same graph as follows. Execute the command:
With the information given above on how to write and execute Mathematica commands, you can now experiment on your own with the Mathematica concepts demonstrated in this tutorial. You may either use the exercises given below, or try some functions of your own choice. If you need to review some information in the previous sections, just scroll up to the appropriate location (or refer to your booklet). Remember, in order to open space to work in after each exercise, you must:
• place the cursor between two cells (get the horizontal cursor),
• click the mouse (a grey line will appear across the window), and
To exit this tutorial, you move the cursor to the Mathematica menu located at the extreme upper left corner of your screen. Point the cursor and click on the "Quit" rectangle at the bottom of the menu . You will be presented with a "Quit" box with some options; click the "Quit Anyway" box.
Once you have left the tutorial, to log off the computer move the cursor to the "Log Out" box of the Workspace Menu (upper left of the screen) and click there. Then on the Quit menu box, click on Log Out.
Below we give a list of Mathematica commands that you will use this year. But first, recall that there are two basic ways to define a function of x. The quick way is, for example:
The lengthier way, but which allows more flexibility, is:
:[font = input; preserveAspect; ]
f[x_] := x^3 + x^2 - 5x - 5
:[font = help; inactive; preserveAspect; ]
Note: both the x _ symbol on the left, and the := defining symbol. Defining f this way allows you to easily evaluate, say, f[2] , f[5 t + 3], etc. In contrast, to evaluate the above y at x = 2 you must type:
:[font = input; preserveAspect; ]
y /. x -> 2
:[font = help; inactive; preserveAspect; ]
Remember that Mathematica tends to do exact arithmetic; for example, carrying the fraction 2358463 / 78932749. This is time-consuming for the computer and one usually prefers the decimal approximation. One way to get the decimal form is to use the N command; e.g.
Should you have another Mathematica notebook open (e.g., Project1.ma), the two notebooks will share the same variables. For example, suppose in another notebook you had defined a variable y differently that we have above. Then you come to this notebook and execute the above y definition. When you return to the other notebook y would be changed to the above.
However, if you simply call in this notebook to refresh your memory on a command, and do no execution, there is no problem.
The following commands are in alphabetical order. If the command is on a separate line, as in the example for D below, you can execute it if you wish; ASSUMING the above y and f[x] have been executed.
Clear---is used to "undefine" variables or functions. This is useful when you are changing the definition of f, or things have gotten confused. For example, Clear[f, y] clears above functions.
Do---allows you to set up a "loop" in order to perform the same (or similar) commands numerous times. E.g., the following does 6 Newton iterations on function t^2 - 5, to approximate Sqrt[5]:
Plot---plots one or more functions over the specified interval. There are many options (try ??Plot), the most common is perhaps PlotRange. E.g. try this with, and without, the option:
Solve---attempts to solve the specified equation (or equations) for the specified variables. Solve is effective primarily for polyomial equations. E.g. this finds x-values at which f[x] and y are equal:
:[font = input; preserveAspect; ]
ourRules = Solve[y == f[x], x]
:[font = help; inactive; preserveAspect; ]
The result of this is a set of "rules", saved in a variable we called `ourRules', which can be used as follows to evaluate y at these x values:
:[font = input; preserveAspect; ]
y /. ourRules
:[font = help; inactive; preserveAspect; ]
Next we solve a pair of equations for unknown s, t:
Sum---this command allows you to conveniently perform a sum, as a `counter ' (k below) takes on its range of values. E.g. to compute the sum of squares of the first six integers: