ADVERTISEMENT

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[1]:= Expand[(x+y)^2]

expression... or factor it back to a compact form.

2

2

Out[1]= x

+ 2 x y + y

or hit control-d

Leave Mathematica (when you’re ready to!)

In[1]:= Exit

In[2]:= Factor[%]

Run Mathematica commands from sample.m

2

% math < sample.m > sample.lst

Out[2]= (x + y)

(non-interactively) with output to sample.lst

% more sample.lst

Find the roots of an equation; note use of ==

In[3]:= Solve[x^2==81,x]

Using Mathematica like a calculator...

(rather than just =) in writing the equation.

Out[3]={{x -> -9}, {x -> 9}}

Mathematica as a good old calculator... hit

Imaginary numbers? No problem...

In[2]:= 27.50-11.92

In[4]:= Solve[x^2==-4,x]

ENTER (or shift-ENTER) after each command

Out[2]= 15.58

Out[4]= {{x -> -2I},{x -> 2I}}

Large values are no problem; you could even

Mathematica can also solve systems of

In[3]:= 15!

In[5]:=Solve[{x+y==1,3x+y==2}]

compute 1500 factorial if you wanted to

algebraic equations in multiple variables.

Out[3]= 1307674368000

1

1

Out[5]= {{x -> -, y -> -}}

Need help with a function? Enter a ? followed

In[4]:= ?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[1]:= Limit[x/(Sqrt[x+1]-1),x->0]

logarithm to base b.

Out[1]= 2

Note that Mathematica functions are case

In[5]:= Log[10,3453.8]

sensitive and begin with a capital letter.

Out[5]= 3.538

Compute a total derivative

In[2]:= Dt[x^3+2x,x]

2

Operations done on whole numbers are

Out[2]= 2 + 3 x

In[6]:= (4000/23)^3

always represented exactly when possible.

64000000000

Partial derivatives work the same way

In[3]:= D[(x^2)(y^3)+4y+x+2,x]

Out[6]= -----------

3

Out[3]= 1 + 2 x y

% means “recall the last result” and //N

12167

means “provide an approximate numerical

In[7]:= %//N

Take the 2nd derivative with respect to x

In[4]:= D[x^3+2x,x,x]

result”

6

Out[7]= 5.26013 10

Out[4]= 6 x

Function args must be put in square brackets.

In[8]:= Sin[60 Degree]

Mathematica can also do integrals, just as

In[5]:= Integrate[3x^2+2x,x]

Trig functions are in radians by default.

Sqrt[3]

you’d expect.

2

3

Out[5]= x

+ x

Want a numeric value? Remember //N

Out[8]= -------

Inverse functions? ArcSin[ ]/Degree

2

Definite integral are also easy to evaluate.

In[6]:= Integrate[E^x,{x,0,1}]

Out[6]= -1 + E

Numerically evaluate an infinite sum.

In[9]:= Sum[i/(i^i),{i,1,\

You can continue long Mathematica

Cartesian space is the default, but not our only

Infinity}]//N

In[7]:= <<Calculus`VectorAnalysis`

commands lines with a \ at the end of a line

option. For example, let’s find the surface area

Out[9]=

1.62847

In[8]:= 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[10]:= BaseForm[223,2]

Out[8]= Cylindrical[Rr,Ttheta,Zz]

Because of the nature of that restriction, it is

(binary).

Out[10]//BaseForm= 11011111

In[9]:= Integrate[Sqrt[1+4Rr^2]\

2

easier to work in cylindrical coordinates. We do

Rr,{Rr,0,1},{Ttheta,0,2Pi}]//N

In[11]:= 16^^FAE7 + 16^^2C3E

so via the vector analysis package (note the

Add FAE7 (hex) to 2C2E (hex); output by

Out[9]= 5.33041

Out[11]= 75557

backtick marks, not apostrophes, used when

default is in decimal, but you can then force

In[12]:= BaseForm[%,16]

loading a package!). Package info is at

that output into hex, too, if you like.

Out12//BaseForm= 12725

16

ADVERTISEMENT

1 votes

Parent category: Education