Assignment Expressions

This notebook is designed to accompany Chapter 3 of "Introduction to Scientific Programming: Computational Problem Solving Using Mathematica and C" by Joseph L. Zachary.  In it, we will use Mathematica to explore assignment expressions.  (31Jul197)

Assignment

When a number is used several times in a notebook, it is better to assign a name to that number, rather than retyping it on every occasion.  This eliminates errors and speeds up your workrate.

For example, suppose we are doing computations that involve the population of the earth like we did in Chapter 2.  Rather than typing the number 5.761*^9 every time it is used, we can assign its value to a variable, say p:

p =  5.761*^9

Similarly, we can assign the land area to a variable, say a:

a =  57.8*^6

The variables a and p will now retain these values for further computations.  For example,  we can  compute the number of persons per square mile as

p/a

Or we could compute the side length of the square (in feet) that each of us get by

5280 * Sqrt[a/p]

Choosing Variable Names

It is a good strategy to pick descriptive names that you can quickly recall.  For example,  suppose we need to solve the population density problem of Chapter 2 for the planets Mars and Venus (assuming a means of sustaining the entire population of the earth on these planets has been found.)    Then it will be good to name these variables as follows:

aEarth  =  57.8*^6aMars  =  56.0*^6aVenus  =  177.7*^6

Now return to the expressions p/a and 5280*Sqrt[a/p] above.   Re-execute them, with the appropriate variable inserted in place of a, to solve the population density problem for Mars and Venus.

Special Symbols

There are a few symbols that have a pre-defined meaning in Mathematica that you may not use as variable names.  Mathematica will warn you should you transgress.  For example

Pi  =  3

The problem is that the symbol Pi is reserved for the mathematical constant 3.14159...  If you evaluate this,

N[Pi]

You will see the first six digits of Pi.

On the other hand, you can assign to pi

pi  =  3

This illustrates that Mathematica differentiates between upper-case and lower-case letters.  All of Mathematica's built-in symbols begin with an upper-case letter, so it is a good idea to arrange for all of the variables that you use to begin with a lower-case letter.