next up previous
Next: More on fsolve Up: No Title Previous: No Title

Combining plots

You have seen how to use the plot command to graph more than one function on a single plot:

   > f := x -> x^2;
   > g := x -> cos(2*x);
   > plot([f(x),g(x)],x=-1..1);
However, this method plots both functions over the same domain. Suppose the functions were defined on different domains, or that you only wanted to plot one of the functions on a small part of its domain (so as not to clutter up the plot). One way to combine plots with different x-ranges is with the display command.
   > with(plots);
   > plotf := plot(f(x),x=-1..1):
   > plotg := plot(g(x),x=-Pi/4..Pi/4):
   > display([plotf,plotg]);
The display command is not automatically loaded when you start Maple; instead it is part of the package ``plots'' and must be loaded separately, using the with command. The output of a with command tells you which new commands have been loaded.

The next two commands show that variables may be assigned to plots, as well as numbers, functions, or expressions. Note that these commands end with a colon, instead of a semicolon. Either punctuation mark tells Maple that the command is complete; however Maple will only produce output if you give it a semicolon. Try executing one of these commands with a semicolon to see why you should use a colon when assigning a variable name to a plot.

If you want to see the plot you've assigned to the variable ``plotf'', just execute the command

   > plotf;
You can also use plots in other commands or expressions, as in the display command above.

Example. The following command shows a curve and several tangent lines, but the tangent lines are kept short to keep from cluttering up the plot.

   > with(plots);
   > f := x -> x^3 - 4x^2 + 4x;
   > plotf := plot(f(x),x=-1..4):
   > tan0 := plot(D(f)(0)*(x-0)+f(0),x=-1..1  ):
   > tan1 := plot(D(f)(1)*(x-1)+f(1),x=0..2  ):
   > tan2 := plot(D(f)(2)*(x-2)+f(2),x=1..3  ):
   > tan3 := plot(D(f)(3)*(x-3)+f(3),x=2..4  ):
   > display([plotf,tan0,tan1,tan2,tan3]);

next up previous
Next: More on fsolve Up: No Title Previous: No Title

Christine M Palmer