Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  Basic Calculations /  Real and Complex Numbers /

4.5 Defining Mathematica Functions

Mathematica TE contains hundreds of built-in mathematical functions like Round, Sqrt, and Sin, and these can be combined to form an endless number of possible expressions. These expressions can be simple like 1/x or more complicated like Abs[Abs[x] - 1]. The first step in Mathematica TE programming is to define a function to abbreviate such an expression. Part 3 describes Mathematica TE's powerful programming language in detail.

This defines the function f. The _ (" blank") after the means that the function's variable is .

In[1]:= f[x_] := 1 / (1 + x^2)

You can evaluate f for any you want, without retyping the expression.

In[2]:= f[2]

Out[2]=

Suppose you give a value.

In[3]:= x = 10

Out[3]=

Evaluating the function doesn't affect the value of .

In[4]:= {f[2/3.], x}

Out[4]=

You can use any argument for f, and you can combine f with any other function, whether built-in or defined.

In[5]:= f[ y + f[Sqrt[y]] ]

Out[5]=

You can do anything with f that you can do with a built-in function like Sin or Sqrt. This plots the function over the range to .

In[6]:= Plot[f[x], {x, -3, 3}]

Out[6]=