1 First Calculations
This is the first part of the eight part Basic Tutorial for learning to use Mathematica. This tutorial is
designed to provide broad experience with Mathematica and to provide a foundation for exploring
advanced features of the system.
No prior experience with Mathematica is assumed or required. The only prerequisites for this tutorial
are familiarity with common operations in elementary mathematics and familiarity with the use of
menus, dialog boxes, and other general features of modern computer software.
This tutorial includes a large number of examples and exercises. It is designed to be used in conjunc-
tion with a copy of Mathematica so that you can experiment with the examples and work out solu-
tions to the exercises. If you are not currently working with a copy of Mathematica then many of the
comments and examples will not apply to you.
In this first part of the Basic Tutorial you will learn about:
Getting Started
To use this tutorial you should know how to start Mathematica, how to switch from one window to
another, how to scroll up and down in a window using the keyboard or a mouse, and how to select
an item from a menu.
If you have had difficulties getting started with Mathematica, or if you are interested in a brief intro-
ductory tour of the system, we recommend the Getting Started guide from the Documentation
Center.
You can open a new window in your copy of Mathematica by selecting New from the File menu. The
appearance of this window will be different in different versions of Mathematica and on different
types of computers, but it is normally an empty window with a title bar across the top, a scroll bar
across the bottom, and a scroll bar on one side.
To enter your input, select the new window by clicking on it, and start typing. Your input will appear
near the top of the window, much as in a typical word processor. Unlike most word processors,
however, you will not see a blinking input cursor until you start typing.
After entering your input, the window will look something like this:
To evaluate your input, press ˜ÎÁÏ (press the return key while holding down the shift key). When
the calculation is finished, the result is displayed just below your input, as in:
You can repeat this process indefinitely with additional inputs. For example, after a second input
and a second evaluation, your notebook might look something like this:
When you are finished with your calculations you can end your Mathematica session (which will
close this window) by selecting Quit from the File menu. Do not select Quit now unless you want to
end this tutorial session.
Syntax Conventions
Basic1.nb 3
Syntax Conventions
For a thorough discussion of Mathematica syntax, and for definitive reference information, see the
Documentation Center, The Mathematica Virtual Book or online help. The summary presented here
is adequate for all of the inputs in this tutorial and for most work with Mathematica.
Calculations are done in Mathematica by evaluating functions. For example, you can use the Plus
function to compute the sum of 2 and 3:
Plus@2, 3D
This calculation is rarely entered this way. This calculation is normally be entered using the more
familiar notation 2 + 3.
2+3
In both of these examples the function that is used is the Plus function, and 2 and 3 are the argu-
ments of the function. 2 + 3 is just another way of entering Plus@2, 3D.
More complicated inputs can be entered using functions as arguments in other functions. For exam-
ple, the product of 7 and 2 + 3 can be entered using the Times function.
Times@7, Plus@2, 3DD
This calculation can also be entered as 7 H2 + 3L. Parentheses are used here for grouping. Enter-
ing 7 and H2 + 3L adjacent to one another indicates that these expressions are to be multiplied.
7 H2 + 3L
Since there is no short notation for Solve, the Solve function is entered in FullForm notation. The
name Solve is followed by square brackets that enclose the arguments of the function. The first
argument is the equation 3 x + 5 ã 14, entered here using special notation for the Equal function.
The Equal function is the function that is used in Mathematica for representing equations. The ã
character is entered as two = signs. The second argument, x, specifies the variable for which to
solve.
The result 88x Ø 3<< illustrates two other special notations. The curly braces { and } are used to
represent List expressions, and the arrow Ø is used to represent a Rule expression. The same
result in FullForm notation is List@List@Rule@x, 3DDD. The use of this type of result will be
discussed later in this tutorial.
The notations that have been introduced so far can be used to enter any system of algebraic equa-
tions. Here is an example showing the use of Solve to solve a pair of equations in two variables.
The pair of equations is entered using a List expression in the first argument of Solve, and the two
variables are specified using the List expression 8x, y< in the second argument of Solve. The
result is a List expression containing the two solutions. Each solution is a list of Rule expressions
that give the values of x and y for that solution.
Solve@8x ^ 2 - 3 y ã 3, 2 x - y ã 1<, 8x, y<D
Here is an example showing the use of the Plot function to plot a sine curve. The first argument
Sin@xD shows the Mathematica notation for the sine of x. The second argument 8x, 0, 2 Pi< is
a List expression that gives the name and the minimum and maximum values of the variable. In
FullForm notation this input would be Plot@Sin@xD, List@x, 0, Times@2, PiDDD. There isn't
an alternate notation for Sin@xD or for the Plot function, but this input is made significantly more
readable and compact by using the alternate notations for List and for Times.
Plot@Sin@xD, 8x, 0, 2 Pi<D
You may want to take some time to experiment with these examples to see the effect of simple
changes. For example, you could try typing your own equation in to the Solve example, or inserting
Cos@xD or some other function in place of Sin@xD in the Plot example. For more information about
these functions, see the documentation for Solve and Plot.
b+cx
You can remove the assigned value of c by evaluating Clear[c], after which c will remain symbolic
during evaluation. It is generally a good idea to clear assignments that are no longer in use so that
the assigned values do not interfere with subsequent calculations.
Basic1.nb 5
You can remove the assigned value of c by evaluating Clear[c], after which c will remain symbolic
during evaluation. It is generally a good idea to clear assignments that are no longer in use so that
the assigned values do not interfere with subsequent calculations.
Clear@cD
b+cx
Assignments can be used for defining constants, for keeping track of intermediate results, and for
defining functions.
Here is an example in which assignments to eq1 and eq2 are used to build up the equations that
are passed to Solve. This way of using assignments to keep track of intermediate results can be
invaluable in large calculations.
eq1 = x ^ 2 - 3 y ã 3
eq2 = 2 x - y ã 1
The notation f[p_] on the left side of the definition is used to indicate that this definition should be
invoked whenever an expression of the form f[expr] is evaluated, where expr is any expression.
For example:
f@9D
Function definitions are used extensively in Mathematica programming, and will be discussed again
in Part 7 and in Part 8 of this tutorial. For now it is necessary only to recognize the use of simple
assignments to define constants and to keep track of intermediate results.
For other examples of the use of assignments, see Assignments
Before continuing, evaluate Clear@eq1, eq2, fD to clear the definitions that were introduced in
this section.
Clear@eq1, eq2, fD
An error in spelling or capitalization of the name of a function is the most common reason for Mathe-
matica returning an input unchanged. The input above using SOLVE rather than Solve is valid
Mathematica syntax, and could be useful if you had, for example, defined your own function and
used SOLVE as the name of that function. In most cases, however, this input is probably an error.
8x, y, z<@@2DD
Parentheses, square brackets, and curly braces are used in a variety of ways in traditional mathemat-
ics and in other computer languages. An occasional source of error in Mathematica is using brack-
ets, braces, or parentheses as they might be used somewhere else.
For example, curly braces and square brackets are sometimes used in traditional mathematics for
grouping arithmetic expressions, and curly braces are often used in computer programming lan-
guages for identifying blocks of statements. Curly braces and square brackets are not used in these
ways in Mathematica. For example, an input such as 7@2 + 3D, which might represent 7 multiplied
by 2 + 3 in traditional mathematical notation, would be very unusual in Mathematica, since the 7
would be interpreted as the name of a function. Similarly, 7 82 + 3< in Mathematica represents 7
multiplied by the list 82 + 3<, which is not the same as multiplying 7 by 2 + 3.
Probably the most prominent departure from traditional mathematical notation in Mathematica is the
use of square brackets rather than parentheses to enclose the arguments of a function. Using
square brackets to enclose function arguments avoids the ambiguity in traditional mathematical
notation between parentheses that enclose function arguments and parentheses that are used for
grouping arithmetic operations. For example, in traditional mathematical notation, y Hx + 1L some-
times indicates y multiplied by x + 1 and sometimes indicates a function y evaluated at x + 1. In
default Mathematica notation, y Hx + 1L always indicates y multiplied by x + 1 and y@x + 1D always
indicates a function y evaluated at x + 1.
For further discussion of these and other aspects of Mathematica syntax, see the corresponding
guide in the Documentation Center.
Looking Ahead
Here is an outline of the parts of this tutorial, and the topic to be covered in each part.
1 First calculations
2 Numerical calculations
3 Symbolic calculations
4 Plotting and graphics
5 Using notebooks
6 Typeset editing
7 Manipulating expressions
8 Programming
Parts 2, 3, and 4 describe the use of standard Mathematica functions for mathematical calculations
Parts 4 and 5 describe the user interface of Mathematica, and facilities for formatting your output.
Parts 7 and 8 provide an introduction to Mathematica programming.
The parts of this tutorial can be read in any order. The order shown in the outline is designed to
provide a broad introduction to the entire system. If you are interested in a specific part of Mathemat-
ica, you may want to skip ahead to the corresponding part of this tutorial. Yet another approach is to
start with the exercises at the end of each part of this tutorial and work back from that point to learn
about the solutions.
You should not skip the exercises, however. Much of the essential information in these tutorials is
covered in the exercises. Even if you do not work out solutions, you should still take the time to read
through the exercises.
Getting Help
8 Basic1.nb
Getting Help
If you would like assistance with this tutorial, experts are available to review your solutions to the
exercises or to answer any questions that come up as you work through this tutorial. You can get
information about assistance with this tutorial by sending an email request for information about
tutorial assistance to Wolfram Research Technical Support (support@wolfram.com).
If you are a registered user of a supported version of Mathematica, you can get help with technical
questions about Mathematica by sending your questions to Wolfram Research Technical Support at
the email address support@wolfram.com, or using contact information included with your copy of
Mathematica.
Exercises
Note: If you are intending to send in your solutions to the exercise for review, we recommending
opening a new notebook and putting your work in the new notebook, rather than editing this tutorial
notebook. You can also include any questions that you have in the new notebook.
-b - b2 - 4 a c -b + b2 - 4 a c
::x Ø >, :x Ø >>
2a 2a
Show how you might use ReplaceAll to replace x by 2 and y by 3 in the list 8x, y<. If you wish,
this input can be entered using the alternate notation for ReplaceAll.
Modify this program to add a column that shows the cube of each integer.
Basic1.nb 9
Modify this program to add a column that shows the cube of each integer.
You can also include an asterisk after the question mark to indicate any sequence of characters.
For example, ? *Plot* will show all names that contain Plot.
Enter ? *Plot* to get the names of all of the functions that include Plot in the name of the
function.
Now enter ? Plot and read the information about the Plot function. This information will be useful
in the next exercise.
The approximate locations of the other two solutions can be seen by plotting the two sides of the
equation on the same graph, and noting the points where the two lines intersect.
Plot@8Sin@xD, 1 - x ê 4<, 8x, - 1, 8<D
By choosing a starting value near the solution that you want, you can cause FindRoot to compute a
value for that solution.