Book Cover

Introduction to Scientific Programming
Computational Problem Solving Using:
Maple and C
Mathematica and C

Author:
Joseph L. Zachary
Online Resources:
Maple/C Version
Mathematica/C Version

Plotting Worksheet

Click below to download a Maple V worksheet. You can look at the appended non-interactive HTML version of the worksheet to learn what the worksheet covers.

This worksheet is designed to accompany Chapter 7 of Introduction to Scientific Programming: Computational Problem Solving Using Maple and C by Joseph L. Zachary. In it, we will look at the plotting examples from Chapter 7 and show how to use optional parameters to embellish the plots. Be sure to experiment with the menus at the top

of the plot windows, as they can change the plot's appearance in various ways.

Getting Started

We'll begin by defining the horizontal, vertical, and duration functions.

(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;

The value of g, which is acceleration due to gravity.

> g := 9.8;

Simple Two-Dimensional Plots

(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=[`sec`, `m`],

> title=`45 degrees; 100 m/sec`);

Exercises

Multiple-Curve Plots

(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=[`sec`, `m`],

> 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=[`sec`, `m`],

> 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=[`sec`, `m`],

> title=`45 degrees; 100 m/sec`);

Exercises

Parametric Plots

(7.33) We create a parametric plot using the dependent expressions from (7.32). We do this by enclosing thetwo 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=[`m`, `m`],

> 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=[`m`, `m`],

> title=`30, 45, and 60 degrees; 100 m/sec`,

> scaling=constrained);

Exercises

Animation

(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. This animation produces a series of two-dimensional plots.

> animate(max(0, vertical(100, angle, t)),

> t=0..duration(100, Pi/2),

> angle=0..Pi/2,

> labels=[`sec`, `m`],

> 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. This animation produces a series of parametric plots.

> animate([horizontal(100, angle, t),

> max(0, vertical(100, angle, t)),

> t=0..duration(100, Pi/2)],

> angle=0..Pi/2,

> labels=[`m`, `m`],

> title=`0..90 degrees; 100 m/sec`);

Exercises