This notebook contains the Mathematica commands from Chapter 3 of Introduction to Scientific Programming by Joseph L. Zachary.

(3.4)  This calculates the circumference of the earth in kilometers, beginning from Eratosthenes's measurements.

360 / 7.2 * 5000. * 0.1575

(3.5)  We can save the value of the expression from (3.4) into the variable "circumference" by using an assignment expression.

circumference = 360 / 7.2 * 5000. * 0.1575

(3.6)  Now that we have given "circumference" a floating-point value, we can use it as if it were a floating-point number.  We can, for example, determine its value.

circumference

(3.7)  We can also use its value in more complicated expressions.

diameter = circumference / 3.14159

(3.8)  Here we recompute "circumference" using parentheses to explicitly group the operands and operators from (3.5).

circumference = (360 / 7.2) * (5000. * 0.1575)

(3.9)  We compute the diameter of the earth using two-digit approximations for its circumference and for pi.  Compare the result with (3.7).

3.9*^4 / 3.1

(3.10)  This is part of an interval arithmetic computation.  We use the smallest possible value (7.15) for the angle measured by Eratosthenes, the largest possible value (5050) for the distance from Alexandria to Cyrene, and the largest possible value for the conversion factor from stadia to kilometers.  This gives us the largest possible value for the circumference of the earth.

(360 / 7.15) * (5050. * 0.15755)

(3.11)  We compute the smallest possible value for the circumference of the earth by peturbing the measurements in the other direction.

(360 / 7.25) * (4950. * 0.15745)

(3.12)  We do an interval arithmetic calculation "by hand" to obtain an upper bound ...

200.5 - 185.5

(3.13) ... and a lower bound.

199.5 - 186.5

(3.14)  Alternatively, we can use Mathematica's built-in "Interval" function, which will do the interval arithmetic calculation for us.

Interval[{199.5, 200.5}] - Interval[{185.5, 186.5}]

(3.15)  We use "Interval" to do the interval arithmetic calculation that we did "by hand" in (3.10) and (3.11).

(360 / Interval[{7.15,7.25}]) *
        (Interval[{4950,5050}] * Interval[{0.15745,0.15755}])