# This worksheet contains the Maple commands from Chapter 7 of # Introduction to Scientific Programming by Joseph L. Zachary. -------------------------------------------------------------------------------- # # (7.7) We use "solve" to find the two times at which a projectile is at # ground level. # > solve(V*t*sin(theta) - (1/2)*g*t^2 = 0, t); -------------------------------------------------------------------------------- # # (7.9) We create a function "horizontal" that returns the horizonal # position in meters of a projectile "t" seconds after it is fired with initial # speed "V" m/sec and initial angle "theta" radians. This function ignores # what happens when the projectile hits the ground. # > horizontal := (V, theta, t) -> V * t * cos(theta); -------------------------------------------------------------------------------- # # (7.10) We create a function "vertical" that returns the vertical position # in meters of a projectile "t" seconds after it is fired with initial speed "V" # m/sec and initial angle "theta" radians. This function ignores what # happens when the projectile hits the ground. # > vertical := (V, theta, t) -> V * t * sin(theta) - 1/2 * g * t^2; -------------------------------------------------------------------------------- # # (7.11) We create a function "duration" that reports the time in seconds # that elapses before a projectile fired with initial speed "V" m/sec and an # initial angle "theta" radians hits the ground. # > duration := (V, theta) -> 2 * V * sin(theta) / g; -------------------------------------------------------------------------------- # # (7.12) The horizontal position of a projectile fired straight up will # always be zero. # > horizontal(100, Pi/2, 10); -------------------------------------------------------------------------------- # # (7.13) We calculate the horizontal position after 10 seconds of a # projectile fired at 45 degrees with a speed of 100 m/sec. # > horizontal(100, Pi/4, 10); -------------------------------------------------------------------------------- # # (7.14) Trigonometric functions such as "cos" give exact answers if their # parameters are exact multiples of pi. # > cos(Pi/4); -------------------------------------------------------------------------------- # # (7.15) The form of this result is a consequence of the observation from # (7.14) ... # > horizontal(100, Pi/8, 10); -------------------------------------------------------------------------------- # # (7.16) ... as is the form of this result. # > horizontal(100, Pi/16, 10); -------------------------------------------------------------------------------- # # (7.17) We use "evalf" to convert the result from (7.13) into # floating-point form. # > evalf(horizontal(100, Pi/4, 10)); -------------------------------------------------------------------------------- # # (7.18) The symbolic constant "g" appears in this result because "g" is # used in the implementation of "vertical" but is nowhere given a value. # > evalf(vertical(100, Pi/4, 10)); -------------------------------------------------------------------------------- # # (7.19) The symbolic constant "g" appears in this result for the same # reason that it appeared in the result of (7.18). # > vertical(100, Pi/4, 10); -------------------------------------------------------------------------------- # # (7.20) This illustrates in a bit more detail what happens when the call to # "vertical" from (7.19) is made. Maple substitutes 100 for "V", Pi/4 for # "theta", and 10 for "t" in the body of "vertical", which results in the # following expression. Maple then evaluates the expression as if it had # been typed in. # > 100 * 10 * sin(Pi/4) - 1/2 * g * 10^2; -------------------------------------------------------------------------------- # # (7.21) We assign "g" a value of 9.8 m/sec/sec. # > g := 9.8; -------------------------------------------------------------------------------- # # (7.22) Now when we repeat (7.18) we get a numerical answer. # > evalf(vertical(100, Pi/4, 10)); -------------------------------------------------------------------------------- # # (7.23) This calculates the duration of the flight of a projectile fired at # 100 m/sec at an angle of 45 degrees. # > evalf(duration(100, Pi/4));\ -------------------------------------------------------------------------------- # # (7.24) We might have chosen to define "vertical" so that acceleration # due to gravity was coded directly in, instead of using the free variable "g" # as we did in (7.10). # > vertical := (V, theta, t) -> V * t * sin(theta) - 1/2 * 9.8 * t^2; -------------------------------------------------------------------------------- # # (7.25) We might also have chosen to define "vertical" so that # acceleration due to gravity was a fourth parameter. # > vertical := (V, theta, t, g) -> V * t * sin(theta) - 1/2 * g * t^2; -------------------------------------------------------------------------------- # # Let's revert to the original definition of "vertical" from (7.10). # > vertical := (V, theta, t) -> V * t * sin(theta) - 1/2 * g * t^2; -------------------------------------------------------------------------------- # # (7.26) Because "t" is symbolic, the result here is given in terms of "t". # > vertical(100, Pi/4, t); -------------------------------------------------------------------------------- # # (7.27) The first parameter to this form of "plot" must be a symbolic # expression in the independent variable. This variable is identified, and its # range specified, by the second parameter. # > plot(vertical(100, Pi/4, t), t=0..20); -------------------------------------------------------------------------------- # # (7.28) The plot from (7.27) shows the height of the projectile as if it # continues falling even after it hits the ground. Here we specify bounds # on "time" that correspond only to the duration of the projectile's flight. # > plot(vertical(100, Pi/4, time),\ time=0..duration(100, Pi/4)); -------------------------------------------------------------------------------- # # (7.29) We repeat (7.28), but use the "labels" and "title" options to give # better labels to the axes and to include a title in the plot. # > plot(vertical(100, Pi/4, time),\ time=0..duration(100, Pi/4),\ labels=[`time (seconds)`, `height (meters)`],\ title=`45 degrees; 100 m/sec`); -------------------------------------------------------------------------------- # # (7.30) We include three different curves in a single plot by specifying # three different dependent expressions as the first parameter to "plot". # (The expressions are enclosed in braces.) Unfortunately, two of the # height curves extend below the ground. # > plot({vertical(100, Pi/6, t),\ vertical(100, Pi/4, t),\ vertical(100, Pi/3, t)},\ t=0..duration(100, Pi/3),\ labels=[`time (seconds)`, `height (meters)`],\ title=`30, 45, and 60 degrees; 100 m/sec`); -------------------------------------------------------------------------------- # # (7.31) We repeat (7.30), but we modify the three dependent expressions # by using "max" to ensure their values are never less than zero. # > plot({max(0, vertical(100, Pi/6, t)),\ max(0, vertical(100, Pi/4, t)),\ max(0, vertical(100, Pi/3, t))},\ t=0..duration(100, Pi/3),\ labels=[`time (seconds)`, `height (meters)`],\ title=`30, 45, and 60 degrees; 100 m/sec`); -------------------------------------------------------------------------------- # # (7.32) On the same plot, we show the horizontal and vertical positions # of a projectile fired at 100 m/sec at an angle of 45 degrees. # > plot({horizontal(100, Pi/4, t),\ vertical(100, Pi/4, t)},\ t=0..duration(100, Pi/4),\ labels=[`time (seconds)`, `position (meters)`],\ title=`45 degrees; 100 m/sec`); -------------------------------------------------------------------------------- # # (7.33) We create a parametric plot using the dependent expressions from # (7.32). We do this by enclosing the two dependent expressions and the # time range in square brackets. The horizontal position is plotted against # the horizonal axis, and the vertical position is plotted against the vertical # axis. Time does not appear explicitly in the plot. # > plot([horizontal(100, Pi/4, t),\ vertical(100, Pi/4, t),\ t=0..duration(100, Pi/4)],\ labels=[`distance (meters)`, `height (meters)`],\ title=`45 degrees; 100 m/sec`); -------------------------------------------------------------------------------- # # (7.34) On the same plot, we put three different parametric plots. We do # this by enclosing three parametric specifications (as in (7.33)) in braces. # We also constrain the plot so that the scales on the two axes are identical. # > plot({[horizontal(100, Pi/6, t),\ vertical(100, Pi/6, t),\ t=0..duration(100, Pi/6)],\ [horizontal(100, Pi/4, t),\ vertical(100, Pi/4, t),\ t=0..duration(100, Pi/4)],\ [horizontal(100, Pi/3, t),\ vertical(100, Pi/3, t),\ t=0..duration(100, Pi/3)]},\ labels=[`distance (meters)`, `height (meters)`],\ title=`30, 45, and 60 degrees; 100 m/sec`,\ scaling=constrained); -------------------------------------------------------------------------------- # # (7.35) Among other things, this gives us access to the "animate" # function. # > with(plots); -------------------------------------------------------------------------------- # # (7.36) We create an animation showing how the height of a projectile # depends on both time and the initial angle of its trajectory. In each # frame of the animation, a plot of the height of the projectile against time # for a particular initial angle is shown. During the animation, the initial # angle varies from 0 to 90 degrees. # > animate(max(0, vertical(100, angle, t)),\ t=0..duration(100, Pi/2),\ angle=0..Pi/2,\ labels=[`time (seconds)`, `height (meters)`],\ title=`0...90 degrees; 100 m/sec`); -------------------------------------------------------------------------------- # # (7.37) We create an animation showing how the trajectory of a # projectile depends on both time and the the initial angle of its trajectory. # In each frame of the animation, a parametric plot of the projectile's # position is shown. During the animation, the initial angle varies from 0 # to 90 degrees. # > animate([horizontal(100, angle, t),\ max(0, vertical(100, angle, t)),\ t=0..duration(100, Pi/2)],\ angle=0..Pi/2,\ labels=[`distance (meters)`, `height (meters)`],\ title=`0..90 degrees; 100 m/sec`); -------------------------------------------------------------------------------- >