Mathematica Notes 1.0: The Basic Environment
Mathematica Notes 1.0: The Basic Environment
Mathematica Notes 1.0: The Basic Environment
Basic Operations
addition +
subtraction −
multiplication *
division /
exponentiation ˆ
factorial !
assignment =
equivalence ==
Test Spin
• Place the cursor over your open notebook and type the following 45/7
<enter>. Apart from the appearance of a cell-bracket on the right, noth-
ing happens.
• Place the cursor over “45/7” and type <shift enter>. Your input is
tagged as such, and the output, also duly-tagged, appears below. The
‘execute’ command in Mathematica is <shift enter>.
• The form of the output might be a little less than exciting. Try another
one - below the output line, type 45/6 and execute (note the incremented
tags). Mathematica is evaluating the input - it will generally try to give
you the most accurate representation of the answer.
• Type N[45/7] and execute it. N[...] returns the value of the argument
as an approximate numerical result.
1
• Type 45/7 //N and execute it. Many commands have a postfix form that
allow them to be used almost as an afterthought.
Built-in Values
• For fun, execute the following two commands: a) N[pi], b) N[Pi]. It may
be all Greek to you and I, but internal values (constants and function
names) within Mathematica all begin with upper-case letters.
√
• You shouldn’t be too surprised, then, that E is Euler’s number, I is −1,
π
Degree is 180 , and Infinity is ∞.
Output Format
• NumberForm[x, n] prints x to n significant figures.
Common Functions
• Sin[x], Cos[X], Tan[x], Csc[x], Sec[x], Cot[x]
2
Variables
• Variables must start with a letter (not a number) and may consist of any
number of alphanumeric characters, Greek letters, even subscripts (use the
basic-input palette). Though there are certainly reasonable exceptions,
user-defined variables should start with a lower-case character (to avoid
conflicts with internally-defined functions). Note that I, E, N , D, C, and
O all have special meanings within Mathematica and should not be used
as variable names.
• You should get in the habit of clearing assigned values when they are no
longer needed (to avoid confusing future calculations). To clear the value
of a, you may execute Clear[a] or a = . .
• Enter c = 1 and d and execute. Note that the last line is not an as-
signment. It is asking you to evaluate the expression stored in d. Not
surprisingly, the result is 13.
• Now, Enter Clear[b] and d and execute. You should still get 17! Why?
(Hint: What is stored in d?)
• It would probably be a good idea to Clear[a,b,c,d] now.
3
• Enter a = 5, b = 7 and d := a + b + c and execute. Immediate calculations
are done for a and b (totally appropriate). No calculation is performed for
d (since delayed assignment tells the computer to perform the calculation
with each invocation).
Equivalence (==)
• Equivalence is used to state that one expression is equal to another (eg.
x2 + y 2 == 25). It does NOT make any assignments.
Multi-Element Assignments
• The list r = {x,y,z} creates a 3-vector ~r with components equal to the
values stored in x, y and z, respectively.
• r[[2]] picks out the second element in r (in this case, y).
• s = r[[{2, 1}]] (Note the list inside the double-bracket.) This will set s to
{y,x}.
• t = m[[2, 1]] (Note the absence of a list inside the double-bracket.) This
sets t to the first element in the second sublist of m (in this case, m2,1 , or
d)
4
Common Matrix Operations
cm multiplication of matrix m by scalar c
m.n multiplication of matrix m by matrix n
Inverse[m] inverse of matrix m
Det[m] determinant of matrix m
Transpose[m] transpose of matrix m
Tr[m] trace of matrix m
Eigenvalues[m] eigenvalues of matrix m
Eigenvectors[m] eigenvectors of matrix m
IdentityMatrix[n] n × n identity matrix
DiagonalMatrix[list] square matrix with the elements of list along the diagonal
MatrixForm[list] displays list in matrix form
Serendipity
• Most of these will be addressed in greater detail later (but are useful to
have now). Use the online help system to expand on these and see what
else you can do!
Help
• ?cmdname should give you help on the particular command “cmdname”.
??cmdname may give you even more. (Execute ?N to learn a little more
about N[. . . ]).
• The ‘Find In Help Browser’ (under the ‘Help’ menu) is also a great re-
source.