CPSC 215

January (16^th), 2001

C. Jacob

Working with the Frontend

Cells and Styles

Entering Text

Entering Formulas and Special Characters

Using Palettes

Simple Definitions for Symbols

Immediate Definitions

a1 = 1

a1 + a2

a2 = a1

a2

a1 + a2

a1 = 3

a2

Delayed Definitions

Delayed definitions (:=) are also used wherever their left-hand side appears. But in this case the evaluation of the right-hand side is delayed until the definition is used. Therefore we do not get an output cell.

a1

a3 := a1

a3

If we change the value of a1 and evaluate a3 again, we get a different result.

a1 = 5

a3

The value of a2, which was set with an immediate definition, has not changed.

a2

We can look at the definitions associated to name by evaluating ?name.

?a3

This shows us that a3 is in the context Global` (see Section 4.4.5) and that the definition a3:=a1 has been set for it.

Immediate vs. Delayed Definitions

Random[]

randomNumber = Random[]

randomNumber

realRandomNumber := Random[]

realRandomNumber

Contexts for Symbols

?a1

?a2

?a3

a1 =.

a1 + a2

?a1

?a2

?Global`*

Contexts[]

Un-assigning, Clearing, and Removing Definitions

a1 = 1;
a2 = 2;

?a1

?a2

Clear[a1, a2]

?a1

?a2

Remove[a1, a2]

?a1

?a2

a1

?a1

Defining Functions

Plot[Sin[(1/x)]/(Sqrt[x]), {x, 0.01, 0.22}];

Plot[Sin[(1/x)]/(Sqrt[x]), {x, 0.01, 0.22}, 
        PlotRange -> {{0, 0.05}, All}];

Assign an Expression to a Symbol

f = Sin[(1/x)]/(Sqrt[x])

Plot[f, {x, 0, (π/8)}];

f

f[π]

f

f /. {x -> π}

% // N

Assign a proper function definition with one variable

func[x_] = Sin[(1/x)]/(Sqrt[x])

func[a]

func[π]

% // N