Introduction to Mathematica

The ’’Wolfram notebook’’

Cells

The graphical or online Wolfram notebook contains program code, text, graphics, or a combination of these.
The notebook consists of embeddable cells, the structure of which can be found as the parentheses to the right. A double click on them closes or opens the given cell.

A new cell can be created by placing the cursor between two cells, a horizontal line will appear, clicking on the line and typing creates a new cells. By default this is a Wolfram program input. Clicking the plus sign on the left side of the horizontal line gives are more options for the cells. For example text. Executing program code in a cell can be done with SHIFT+ENTER.

Wolfram input (default)

1+1

In[n] and Out[n] means the nth in- and output. The previous output is %, the kth is %k.

%1+2

Basics:

The order of the basic mathematical operators is the same order used in mathematics.

2+3^5
(2+3)^5

Functions start with capital letters and the arguments are written inside [ ] brackets.

Sin[Pi]

Lists are created with the { } brackets, the elements are separated with commas.

{1,Pi,a, Cos,5,7}

List indices are written inside [[ ]] (double square brackets) .

2^10+Sin[Pi/2]

{1,2,3,4,5}[[3]]

There is text completion:

Si

Palettes offer some more help. For example a simple limit can be written with the palettes:

Limit[Sin[x]/x,x->0]

The plot of a multi variable function!

Plot3D[Sin[x]Cos[y],{x,-2Pi,2Pi},{y,-2Pi,2Pi}]

Mathematica as a numeric calculator

Numerical calculations

We can compute precise values, like a symbolic calculator:

12345/3^10

We can do numeric approximation with the N function:

N[%,30]

If the input is a floating point number then the output will be a float as well:

12345.0/3^10

(({{3, 4}, {5, 6}}))

Det[%]

Variables

a=12345/3^10

Mathematical symbols can be found on the palette, or with hotkeys (for example. CTRL-2 for square root):

a=(Sqrt[1234])

Expand[(a+b)^2]

Clear[a]

A lot more can be found on the Fast introduction for math students page.

Lists

The most important constructs in Mathematica are lists.

Range[5]

Range[0,1,1/10]

ListPlot[Join[Range[5],Reverse[Range[5]],Range[5]]]

Join[{1,3,5},Range[4]]

Elementary operations:

{1,3,5}+2

a={1,3,5}*{2,3,1}

Sort[a]

Length[a]

Total[a]

Part[a,2]

Min[a]

Table[2,5]

Table[n^3,{n,0,1,0.1}]

Table[{1,x,x^2,x^3},{x,4}]

RandomInteger[5,20]+1

b=Range[10]

b[[2;;4]]

b[[2;;9;;3]]

b[[-2]]

Mathematica as a symbolic calculator

Defining functions

A := delayed evaluation, the _ is the symbol for the variable that will be substituted:

Clear[x]

f[x_]:=x^3-x

x

f[x]

f[1.5]

a=3
f[a]

Clear[f]

f[abc]

Solve[f[x]==24,x]

f[x]

Factor[f[x]-24]