Get Started »

# Variables & Functions

Variables start with letters and can also contain numbers:

(It’s best to start with lowercase letters, reserving capitals for built-in objects.)
 In[1]:= ⨯ `a1/2`
 Out[1]=

A space between two variables or numbers indicates multiplication:

(In other words, “a b” is a times b, whereas “ab” is the variable ab.)
 In[2]:= ⨯ `a b + 5 x x`
 Out[2]=

Use /. and `` to make substitutions in an expression:

(The “rule” `` can be typed as ->.)
 In[3]:= ⨯ `1 + 2 x /. x -> 2`
 Out[3]=

Assign values using the = symbol:

 In[1]:= ⨯ `x = 2`
 Out[1]=

Use your variable in expressions and commands:

 In[2]:= ⨯ `1 + 2 x`
 Out[2]=

Clear the assignment, and x remains unevaluated:

 In[3]:= ⨯ ```Clear[x] 1 + 2 x```
 Out[3]=

Define your own functions with the construction f[x_]:=

 In[1]:= ⨯ `f[x_] := 1 + 2 x`

x_ means that x is a pattern that can have any value substituted for it.

:= means that any argument passed to f is substituted into the right-hand side upon evaluation:

 In[2]:= ⨯ `f[2]`
 Out[2]=

QUICK REFERENCE: Defining Variables and Functions `»`