# This worksheet contains the Maple commands from Chapter 2 of # Introduction to Scientific Programming by Joseph L. Zachary. -------------------------------------------------------------------------------- # # (2.1) The simplest kind of a expression is a number. It evaluates to itself. # > 57.8; -------------------------------------------------------------------------------- # # (2.2) This ill-formed number is an example of a syntax error. Since # Maple cannot make sense of it, it reports an error. # > 5.7.8; -------------------------------------------------------------------------------- # (2.3) Here we compute the quotient of two rational numbers. Notice # that the answer is expressed as an exact fraction in lowest terms. # > 57800000 / 5761000000; -------------------------------------------------------------------------------- # # (2.4) We do the same computation as in (2.3), but this time using # floating-point numbers. We know these are floating-point numbers # because they contain decimal points. The answer is rounded off to ten # digits, not counting the leading zero. # > 57800000. / 5761000000.; -------------------------------------------------------------------------------- # # (2.5) We do the computation from (2.3) and (2.4) one more time, this # time using scientific notation to write the floating-point numbers. # > 57.8e6 / 5.761e9; -------------------------------------------------------------------------------- # # (2.6) We illustrate that floating-point arithmetic is not exact by # multiplying the quotient from the previous example by the divisor. The # number that we get back is almost, but not exactly, the same as the # dividend. # > .01003298039 * 5.761e9; -------------------------------------------------------------------------------- # # (2.7) Here we square a rational number by using the exponentiation # operator. # > 5280^2; -------------------------------------------------------------------------------- # # (2.8) This example shows how more than one arithmetic operation can # be carried out in a single expression. Because all of the numbers # involved are floating-points, the result is expressed as a rational number. # > .01003298039 * 27878400.; -------------------------------------------------------------------------------- # # (2.9) We repeat the computation from (2.8) using rational numbers. # > 289/28805 * 27878400; -------------------------------------------------------------------------------- # # (2.10) Here we divide two floating-point numbers (obtaining an # intermediate floating-point result), square a rational number (obtaining # an intermediate rational result), and then multiply the two intermediate # results. Because the final multiplication involves both a floating-point # number and a rational number, the rational number is first converted to # floating-point form. # > (57.8e6 / 5.761e9) * (5280^2); -------------------------------------------------------------------------------- # # (2.11) This is an example of the use of the "sqrt" built-in function. It # returns the square root of its parameter. # > sqrt(279703.4405); -------------------------------------------------------------------------------- # # (2.12) The parameter to "sqrt" can be an arbitrary expression. Here we # take the square root of the value of an expression that involves division, # exponentiation, and multiplication. # > sqrt((57.8e6 / 5.761e9) * (5280.^2)); -------------------------------------------------------------------------------- # # (2.13) Here we take the same square root as in (2.12), but we use # rational numbers. An exact result is given using a radical. # > sqrt((57800000 / 5761000000) * (5280^2)); -------------------------------------------------------------------------------- # # (2.14) The "evalf" built-in function converts a rational number into # floating-point form. # > evalf(17952/5761 * sqrt(28805)); -------------------------------------------------------------------------------- # # (2.15) There is a limit on the sizes of rational numbers that can be # computed. Although the limit varies from computer to computer, this # expression will probably exceed the limit on your computer. # > 10^600000; -------------------------------------------------------------------------------- # # (2.16) If 10e300000 and 10e(-300000) are acceptable rational numbers # on your computer, this expression will evaluate to 1. # > 10^300000 * 10^(-300000); -------------------------------------------------------------------------------- # # (2.17) This expression, however, should cause an overflow. # > 10^(-300000) * 10^(-300000); -------------------------------------------------------------------------------- # # (2.18) This one should cause an overflow also. # > 10^300000 * 10^300000; -------------------------------------------------------------------------------- # # (2.19) A compound expression will cause an overflow if any of the # intermediate results cause an overflow. For example, this will probably # cause an overflow. # > (10^524279 * 2) * 10^(-524279); -------------------------------------------------------------------------------- # # (2.20) Depending on the limits imposed on rational numbers on your # computer, this expression may not cause an overflow. # > 10^524279 * (2 * 10^(-524279)); -------------------------------------------------------------------------------- # # (2.21) The limits on floating-point numbers are less restrictive than the # limits on rational numbers. This probably won't cause an overflow. # > 10.^600000000.; -------------------------------------------------------------------------------- # # (2.22) But this probably will cause an overflow. # > 10.^6000000000.; -------------------------------------------------------------------------------- # # (2.23) The exact answer to this calculation should be 15241383936, but # Maple rounds it to ten digits. # > 123456.^2.; -------------------------------------------------------------------------------- # # (2.24) The evalf function takes an optional second parameter, which is # the number of digits to include in the floating-point result. # > evalf(17952/5761 * sqrt(28805), 15); -------------------------------------------------------------------------------- >