next up previous
Next: Saving worksheets Up: Maple introduction Previous: On your own

Another approach

There are often several ways to approach a problem in Maple. There is nothing wrong with what we did earlier to solve the projectile problem, but there are other ways to do the same thing. In this section we describe a different way to do the problem that involves less typing and is probably more efficient.

The idea here is to only fix the values of parameters that are not likely to change. For other parameters we use a set of values that can easily be changed and the Maple subs command for substituting their values.

Another worksheet has been prepared that uses this different approach. You should load it by using the Open... command from the File menu to load the following file.

/usr7/bfarr/Maple/projectile2.ms
The first thing to notice is that the worksheet you have just loaded shows all of the output from the Maple commands. However, this doesn't mean that the results of the commands are available to the Maple computational engine. All it really means is that the output of the commands was saved as part of the worksheets. The internal workings of Maple needed to produce that output were not saved. Thus, you must execute the commands.

The first command in the worksheet you loaded sets the value of g to be 9.8 and is exactly the same as in the first worksheet. The next line, however, is very different and looks like the following.

  > par_vals := {v0 = 20, x0 = 0, y0 = 1, theta = Pi/6};

displaymath363

Maple uses curly braces ({}) to denote a set, so what this command does is provide a set of values of the parameters. We've also given the set a label, par_vals, so we can use this set of values later on.

The most important point is that this command does not fix the values of the parameters. That is, v0 and the other parameters are still variables as far as Maple is concerned. What we have done is define a set of particular values of the parameters. We will see below how to use this set of values.

The next two commands just define the functions x(t) and y(t); they are identical to the commands we used before. Next come the two commands below.

  > x(0);

displaymath364

  > y(0);

displaymath365

These commands demonstrate that the values of the parameters tex2html_wrap_inline269 and tex2html_wrap_inline271 have not been set.

The following command is the same one we used before to solve for the value of t for which y(t) = 0. Note, however, that the parameters tex2html_wrap_inline247 , tex2html_wrap_inline249 , tex2html_wrap_inline269 , and tex2html_wrap_inline271 appear as variables and not as numbers. This means that this is a more general solution than the one we got before. To evaluate it for specific values of the parameters, we just have to substitute them into the solution.

That is precisely what the Maple subs (for substitute) command does, as shown below.

  > simplify(subs(par_vals,x(t_hit[2])));

displaymath366

The simplify command is needed because Maple doesn't automatically simplify the result of the subs command. You can see what happens without it by removing the simplify command and submitting the command without it.

The syntax for the subs command is as follows

subs(values, expression);
where values is a set of equations giving values for variables and expression is a Maple expression or function into which the values are to be substituted.

One advantage to this approach is that you can have several sets of parameter values around. For example, suppose we want to let tex2html_wrap_inline249 vary, as we did before, and study how the distance the projectile travels depends on tex2html_wrap_inline249 . We can do this very simply by just defining a new set of parameter values that doesn't include tex2html_wrap_inline249 . The commands below show how to do this, and how to plot the distance the projectile travels versus the angle tex2html_wrap_inline249 .

  > par_vals2 := {v0 = 20, x0 = 0, y0 = 1};

displaymath367

  > plot(subs(par_vals2,x(t_hit[2])),theta=0..Pi/2);

next up previous
Next: Saving worksheets Up: Maple introduction Previous: On your own

Sean O Anderson
Wed Sep 4 09:48:47 EDT 1996