# This worksheet contains the Maple commands from Chapter 5 of # Introduction to Scientific Programming by Joseph L. Zachary. # # We set the mantissa length to 4. # > Digits := 4; # # (5.3) When we try computing the distance to the horizon using the # straightforward approach and four digits of mantissa, we get zero as # an answer. # > sqrt((2.09e7 + 66)^2 - 2.09e7^2); # # (5.4) This shows what went wrong with example (5.3). With only four # digits of mantissa, adding 66 feet to the radius of the earth has no # effect. # > 2.09e7 + 66; # # (5.7) When we try computing the distance to the horizon using the # improved approach and four digits of mantissa, we get an answer that # is correct to four digits. # > sqrt(2 * 2.09e7 * 66 + 66^2); # # For the remainder of the worksheet we set the mantissa size back to # 10. # > Digits := 10; # # (5.8) This repetition of the calculation from (5.7) using a hill size # of 100 feet helps to motivate the utility of programmer-defined # functions. # > sqrt(2 * 2.09e7 * 100 + 100^2); # # (5.9) We define a function called horizon that encapsulates the types # of calculations done in (5.7) and (5.8). # > horizon := (R, h) -> sqrt(2*R*h + h^2); # # (5.10) We use horizon to compute the distance to the horizon from the # top of a 100 foot hill. The answer is the same as in (5.8). # > horizon(2.09e7, 100); # # (5.12) We use horizon to compute the distance to the horizon from # Kill Devil Hill using interval arithmetic. This is the maximum # possible distance ... # > horizon(2.095e7, 66.5); # # (5.13) ... and this is the minimum possible distance. # > horizon(2.085e7, 65.5); # # (5.15) We create a programmer-defined function "horizonFast" to # calculate the distance to the horizon using an algebraically suspect # but computationally acceptable approximation. # > horizonFast := (R, h) -> sqrt(2*R*h); # # (5.16) We use horizon to compute the distance to the horizon from # Kill Devil Hill at high tide ... # > horizon(2.09e7 + 5, 66 - 5); # # (5.17) ... and at low tide. # > horizon(2.09e7 - 5, 66 + 5); # # (5.18) We compute the distance to the horizon from Kill Devil Hill # when our eyepoint is three feet above the summit. # > horizon(2.09e7, 69); >