# "Mathematica" Cheat Sheet

Just Enough Mathematica to Make you Dangerous
Joe St Sauver, Ph.D. (joe@oregon.uoregon.edu)
Algebra...
Use ssh to get to the % prompt
Mathematica can expand an algebraic
% math
In:= Expand[(x+y)^2]
expression... or factor it back to a compact form.
2
2
Out= x
+ 2 x y + y
or hit control-d
Leave Mathematica (when you’re ready to!)
In:= Exit
In:= Factor[%]
Run Mathematica commands from sample.m
2
% math < sample.m > sample.lst
Out= (x + y)
(non-interactively) with output to sample.lst
% more sample.lst
Find the roots of an equation; note use of ==
In:= Solve[x^2==81,x]
Using Mathematica like a calculator...
(rather than just =) in writing the equation.
Out={{x -> -9}, {x -> 9}}
Mathematica as a good old calculator... hit
Imaginary numbers? No problem...
In:= 27.50-11.92
In:= Solve[x^2==-4,x]
ENTER (or shift-ENTER) after each command
Out= 15.58
Out= {{x -> -2I},{x -> 2I}}
Large values are no problem; you could even
Mathematica can also solve systems of
In:= 15!
In:=Solve[{x+y==1,3x+y==2}]
compute 1500 factorial if you wanted to
algebraic equations in multiple variables.
Out= 1307674368000
1
1
Out= {{x -> -, y -> -}}
Need help with a function? Enter a ? followed
In:= ?Log
2
2
by the name of a Mathematica function. Not sure
Log[z] gives the natural
of a function’s name? You can use a * to see
Calculus...
logarithm of z (logarithm to
possible matches, e.g., ?L*
base e). Log[b, z] gives the
Evaluate a limit
In:= Limit[x/(Sqrt[x+1]-1),x->0]
logarithm to base b.
Out= 2
Note that Mathematica functions are case
In:= Log[10,3453.8]
sensitive and begin with a capital letter.
Out= 3.538
Compute a total derivative
In:= Dt[x^3+2x,x]
2
Operations done on whole numbers are
Out= 2 + 3 x
In:= (4000/23)^3
always represented exactly when possible.
64000000000
Partial derivatives work the same way
In:= D[(x^2)(y^3)+4y+x+2,x]
Out= -----------
3
Out= 1 + 2 x y
% means “recall the last result” and //N
12167
means “provide an approximate numerical
In:= %//N
Take the 2nd derivative with respect to x
In:= D[x^3+2x,x,x]
result”
6
Out= 5.26013 10
Out= 6 x
Function args must be put in square brackets.
In:= Sin[60 Degree]
Mathematica can also do integrals, just as
In:= Integrate[3x^2+2x,x]
Trig functions are in radians by default.
Sqrt
you’d expect.
2
3
Out= x
+ x
Want a numeric value? Remember //N
Out= -------
Inverse functions? ArcSin[ ]/Degree
2
Definite integral are also easy to evaluate.
In:= Integrate[E^x,{x,0,1}]
Out= -1 + E
Numerically evaluate an infinite sum.
In:= Sum[i/(i^i),{i,1,\
You can continue long Mathematica
Cartesian space is the default, but not our only
Infinity}]//N
In:= <<Calculus`VectorAnalysis`
commands lines with a \ at the end of a line
option. For example, let’s find the surface area
Out=
1.62847
In:= SetCoordinates[\
Cylindrical]
2
2
2
2
of the parabola z=1+x
+y
where x
+y
<=1.
Convert the value 223 (decimal) to base 2
In:= BaseForm[223,2]
Out= Cylindrical[Rr,Ttheta,Zz]
Because of the nature of that restriction, it is
(binary).
Out//BaseForm= 11011111
In:= Integrate[Sqrt[1+4Rr^2]\
2
easier to work in cylindrical coordinates. We do
Rr,{Rr,0,1},{Ttheta,0,2Pi}]//N
In:= 16^^FAE7 + 16^^2C3E
so via the vector analysis package (note the
Add FAE7 (hex) to 2C2E (hex); output by
Out= 5.33041
Out= 75557
backtick marks, not apostrophes, used when
default is in decimal, but you can then force
In:= BaseForm[%,16]
loading a package!). Package info is at
that output into hex, too, if you like.
Out12//BaseForm= 12725
16