Getting Started with MATHEMATICA
|
|
This short primer consists primarily of examples intended to illustrate
basic features of the mathematical software package MATHEMATICA.
For optimal use, it is suggested that you initiate a MATHEMATICA session and attempt to carry out the
examples that are discussed.
- Starting and Stopping.
- To start:
Sit down at a PC or MAC in any of the A&S Computer Labs and choose
MATHEMATICA from the Windows Start menu or icon
grouping.
- To stop:
select Exit from the
File menu in the upper left corner of the MATHEMATICA window.
- Getting help:
There is a very extensive and well-organized Help facility built into
MATHEMATICA. This may be accessed by choosing Help Browser...
from the
Help menu in the upper right corner of the MATHEMATICA window. An even
better way to get help is to consult an experienced MATHEMATICA user.
-
Compiling and Editing.
- Once you have typed in a command, Shift-Enter will send the
command to MATHEMATICA. For example, try typing Expand[(x+y)^2]
and Shift-Enter. Then try
Expand[(x+y)^50].
(Note: Shift-Enter means to simultaneously hold down the
Shift and Enter keys.)
- While MATHEMATICA is compiling the input, you will see "evaluating" written at the bottom of the
screen. If "evaluating" remains there for a long time you have probably given
MATHEMATICA a problem that involves too many calculations, often you can
interrupt the calculation by
choosing "Abort Evaluation" from the "Kernel" menu.
- Return (or
Enter) starts a new line on your screen but DOES NOT
invoke MATHEMATICA. Use this to keep your lines from scrolling too far
to the right, epecially if you are planning to make a print-out of your session.
- For WINDOWS users: If previous text is blocked off using the mouse it can be
copied using Control-c
and then Control-v ,
after repositioning the cursor where you want to insert the blocked text.
- To prepare a MATHEMATICA session for printing, you will likely want to delete any cells that
were incorrect or irrelevant to the problem at hand. You will notice that each cell has an associated
bracket shown on the right edge of the screen. If you single click the mouse on one brackets and then type
Control-x this will delete the corresponding cells or groups
of cells. If you double click on a bracket it will keep the cell but hide it (or if the cell is
currently hidden this will redisplay it).
- You can create titles or subtitles for your document by choosing the appropriate command from the
Format menu. In this menu you'll find options for choosing fonts, font sizes, background colors and
etc.
-
Basic Commands.
- Commands and functions in MATHEMATICA always start with a capital letter.
And arguments are always enclosed in square brackets " [ ]",
not round parentheses. For example, try compiling the command
Log[1] or
ArcSin[1]. Then, for comparison,
compile the commands
Log(1) and
ArcSin(1).
- Parentheses
(round brackets " ( )") should be used to make sure that
operations are computed in the desired order. For example, compare the outcome of
1/2 * 2 with 1/(2 * 2).
- The percent sign % can be used as a shorthand
to denote the last result generated, and %% is the
second-to-last result. On the other hand,
%7 would represent the output result in the output
line number 7, and so on.
- A semi-colon " ; " at the end
of a line will suppress the MATHEMATICA output. (So MATHEMATICA does the computation but doesn't
print it to the screen.)
-
Elementary Functions.
- Either x * y or
x y (with a blank space inserted
between x and y) denotes multiplication of x by y. If you write
xy without a space
between the x and y then MATHEMATICA will attempt to interpret this as
the name of a single variable (and it will NOT interpret it as multiplication).
(However, if, in the above, x is replaced by an actual number then MATHEMATICA
will interpret the juxtaposition as multiplication.
For example, 5y
means the same as 5 * y , but
x5 will again be interpreted as a variable name.)
- For exponents, write x^7
for x7, and so on.
- The common constants and
e are denoted by Pi and
E respectively in MATHEMATICA.
- Basic elementary functions are invoked by Sin[x], Cos[x],
Sinh[x], Sec[x], Tan[x], ArcSin[x], ArcTan[x], Sqrt[x], Log[x], Exp[x], and etc.
The interpretations of these functions should be obvious. Note that Log[x]
is used for the natural logarithm function ln(x).)
- Write N[ Sqrt[2] ] to get an approximation to
,
or N[ Sqrt[2] , 30 ] to get an approximation accurate to
30 decimal places.
-
Algebra and Calculus.
Try having MATHEMATICA compile each of the following to see what
happens:
- Expand[ (x+y+z)^2 ]
- Factor[ x^3 + 2x^2 - 5x - 6 ]
- Simplify[ Sin[x]^2 + Cos[x]^2 ]
- Integrate[ x^5 * Sin[x] , x ]
- NIntegrate[ E^(x^2), {x, 0, 3} ]
(This numerically approximates the definite integral
.)
- D[ Log[x] * Sin[x], x ]
(This computes the derivative with respect to x.)
- D[ Log[x] * Sin[x], {x,3} ]
(This computes the third derivative with respect to x.)
- Solve[ x^2 + x - 1 == 0, x ]
(Note: == is a doubled equal sign, its always used for Logical Equality.)
- Limit[ Sin[x]/x, x -> 0 ]
(So MATHEMATICA knows L'Hospital's Rule!)
-
Fundamentals of Graphing.
Try having MATHEMATICA compile each of the following to see what
happens:
- Plot[ Cos[x^2] , {x,-Pi,Pi} ]
This gives the graph of y=cos(x2) on the interval
. You can get MATHEMATICA to
enlarge the picture by first clicking on the graphic output and then
dragging one of the little black rectangles while holding down the left
mouse button.
- Plot[ Cos[ x^2 ] , {x, -Pi, Pi},
PlotRange -> { 0,1 } ]
- Plot[ Cos[ x^2 ] , {x, -Pi, Pi},
AxesLabel -> {"x-axis", "y-axis"},
Frame -> True, PlotLabel -> {"My graph"} ]
- Plot3D[ x^2 - y^2 , {x, -3, 3}, {y,-3,3}]
More details on controlling the output of the "Plot"
command can be found on the 2-dimensional plotting page.
Graphing functions of two variables is discussed on the
"Plot3D" command page.
URL: http://math.ou.edu/~amiller/math/mathint.htm
August 23, 2000