Application Center - Maplesoft

App Preview:

Maple Essentials: Section 3: Graphing

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

section3.mws

Section 3: G raphing

In this section you will learn how to plot the graph of a function defined by an expression. Other topics covered include: combining the graphs of several expressions into a single plot, plotting points, and combining different plot structures into a single picture.

>    restart;

>   

Plotting an Expression: the plot  command

Example 1

We use the plot  command to plot the graph of   3*x^2-8   for  x  between - 5 and 5 .

>    plot(3*x^2-8,x=-5..5);

[Maple Plot]

>   

Notice that Maple scales the y -axis automatically, choosing a y -scale that shows the entire graph corresponding to the specified domain.

You can override automatic y -scaling by specifying a range for y  as well as x . On the next line we have limited the y -range to the interval [-20,40].



>    plot(3*x^2-8,x=-5..5,y=-20..40);

[Maple Plot]

>   

If you click on a graph with the left mouse button, the graph is selected and the bottom toolbar options are changed.  See the reference diagram below.  Now when you click on the graph, the point coordinates of its location are shown.  The 1:1 button makes the x -scale and y -scale equal.  

Scroll back up  to the previous graph and experiment with these features.  Try the other graph options as well.

Example 2

Automatic scaling is a useful feature but there are times when you may want to set the y  range manually. For example automatic scaling isn't appropriate for graphs with vertical asymptotes.

Compare the next two graphs.

>    plot(x/(x-2),x=-5..5);

[Maple Plot]

>   

Notice how we have set the limits for y to the interval [-20,20] in the following plot  command.

>    plot(x/(x-2),x=-5..5,y=-20..20);

[Maple Plot]

>   

Example 3

Plot the graph of    y = x^3+1-exp(x)  over the domain [-8, 8]. Choose a   y -range that allows you to see the four x -intercepts.

First let's take a look at the plot with automatic scaling of y .

>    plot(x^3+1-exp(x),x=-8..8);

[Maple Plot]

>   

The large negative values for y  near 8 have forced the vertical scale to be too large to see the x -intercepts clearly.

A better view is achieved by setting limits on the y -range.

>    plot(x^3+1-exp(x),x=-8..8,y=-5..15);

[Maple Plot]

>   

Exercise 3.1

Plot y = sin(x)  over two  complete periods.

Student Workspace 3.1

>   

>   

>   

>   

Answer 3.1

>    plot(sin(x),x=-2*Pi..2*Pi);

[Maple Plot]

>   

or

>    plot(sin(x), x=0..4*Pi);

[Maple Plot]

>   

Exercise 3.2

Plot   y = 3*x^4-6*x^2  over the domain [-10,10] with automatic y -scaling.  

After observing the graph, edit the domain and range so that you can see the x -intercepts clearly.  Estimate the x -intercepts with the mouse cursor.

Student Workspace 3.2

>   

>   

>   

>   

Answer 3.2

>    plot(3*x^4-6*x^2,x);

[Maple Plot]

>   

Notice how large y  becomes when   x  = -10 or   x  = 10;  with automatic y  scaling it is difficult to see how the function behaves for x  between -2 and 2.  In the next plot we restrict the y -scale in order to focus on the behavior for small y .

>    plot(3*x^4-6*x^2,x=-3..3,y=-5..15);

[Maple Plot]

>   

The x -intercepts are about -1.4, 1.4 and 0.

>   

Plotting Several Expressions

To show more than one graph in the same picture list them in square brackets [  ] separated by commas.

>    plot([cos(x),x^2],x=-1..4,y=-4..4);

[Maple Plot]

>   

Notice that each of the graphs is displayed using a different color. You can specify the colors for each function by adding a color option at the end of the command. The colors are assigned in the same order as the functions. Note that the colors must also be listed in a square bracket [  ] . Here is an example.

>    plot([cos(x),x^2],x=-1..5,y=-4..4,color=[blue,black]);

[Maple Plot]

>   

Here are the colors available in Maple.

aquamarine black  blue      navy   coral cyan  
brown      gold   green     gray   grey  khaki
magenta    maroon orange    pink   plum  red   
sienna     tan    turquoise violet wheat white
yellow      

          

Exercise 3.3

Graph the functions y = x^2-5*x+6   and   y = 1/((x-2)^2)  together. Experiment with different y ranges so that complete pictures of both graphs are shown.

Student Workspace 3.3

>   

>   

>   

>   

>   

>   

>   

Answer 3.3

>    y1 := x^2-5*x+6;

y1 := x^2-5*x+6

>   

>    y2 := 1/(x-2)^2;

y2 := 1/((x-2)^2)

>   

>    plot([y1,y2],x=-3..8,y=-1..6);

[Maple Plot]

>   

Plotting points

The plot command can also plot one or more points.

Example 1

Plot the point (2, 3) .  Note in the following line that we use two sets of square brackets.

>    plot([ [2,3] ],style=point);

[Maple Plot]

>   

Example 2

We can control the size of the x-  and y- ranges shown by adding these to the command as in the next line.

>    plot([ [2,3] ],x=-7..7,y=-7..7,style=point);

[Maple Plot]

>   

Example 3

To graph more than one point list them in the plot  command. Note the commas. Remember square brackets for each point and an extra pair of square brackets surround the list.

>    plot([ [2,3],[-2,5],[1,-4] ],x=-7..7,y=-7..7,style=point);

[Maple Plot]

>   

Example 4

Changing style to "line" connects the points in the order listed.

>    plot([ [2,3],[-2,5],[1,-4] ],x=-7..7,y=-7..7,style=line);

[Maple Plot]

>   

Example 5

Optional extensions can be used to specify point color and symbol (e.g. diamond, circle, cross is default) to indicate the points.

>    plot([[3,2],[-2,3],[2,-1]],style=point,color=blue,symbol=circle);

[Maple Plot]

>   

Exercise 3.4

Plot the following points using the color red and the diamond symbol:  [1, 4] , [-2, -3], [4, -5] and [-6, 5] .

Then connect the points with lines in a separate plot  command.

Student Workspace 3.4

>   

>   

>   

>   

>   

>   

Answer 3.4

>    plot([[1,4],[-2,-3],[4,-5],[-6,5]],style=point,color=red,symbol=diamond);

[Maple Plot]

>   

>    plot([[1,4],[-2,-3],[4,-5],[-6,5]],style=line,color=red,symbol=diamond);

[Maple Plot]

>   

Combining Graphs of Expressions and Points: the display  command

A special plotting package called plots  contains many additional graphing features.   To use these commands, you need to execute the following line which loads plots .  Recall, the colon at the end of the statement allows this line to be executed without displaying any distracting output.  To see the contents of plots  you can change the colon to a semicolon.

>    with(plots):

Warning, the name changecoords has been redefined

>   

The display   command allows you to combine graphs of expressions and points in the same picture. The first step is to name the individual picture components.

IMPORTANT: Be sure to use a colon  at the end of the line to suppress output (see first three lines below).  The display  command is then used to do the actual plot (this ends with a semicolon).  

>    pict1 := plot([-3*x+5,9-x^2],x=-3..5,color=[green,red]):

>   

>    pict2 := plot([[-1,8],[4,-7]],style=point,color=blue,symbol=circle):

>   

>    display([pict1,pict2]);

[Maple Plot]

>   

Alternatively we can list these three related plot  commands in a single execution group by typing [Shift] + [Enter]  at end of each line.

>    pict1 := plot([-3*x+5,9-x^2],x=-3..5,color=[green,red]):
pict2 := plot([[-1,8],[4,-7]],style=point,color=blue,symbol=circle):
display([pict1,pict2]);

[Maple Plot]

>   

For more on this see " Execution groups with more than one command" in the section  Notes on the Maple Worksheet Interface at the end of this tutorial.

>   

Exercise 3.5

Display a graph that contains both the function   y = x^2+x-6   and its x-  and y- intercepts, marked with circles.

Student Workspace 3.5

>   

>   

>   

>   

>   

>   

Answer 3.5

>    pict4 := plot(x^2+x-6,x=-5..4,y=-8..8):

>   

>    pict5 := plot([[0,-6],[-3,0],[2,0]],style=point,symbol=circle, color=blue):

>   

>    display([pict4,pict5]);

[Maple Plot]

>   

Interactive Graphing

In this section, you will see that Maple has tools you can use to plot graphs. Using smartplots or interactive tools, you can plot easily without having to specify details in the plot  command.

Using smartplot  command

The smartplot  command generates an initial plot which can be further tailored through use of interactive controls.

Here is an example. To plot f(x) = sin(x) , type and execute:

>    smartplot(sin(x));

[Maple Plot]

>   

By right-clicking on the graph, you can now adjust the details as you want.

For example, to change the domain to -4..4, right-click anywhere on the graph.

Select Axes then Range. The Axes Ranges window will pop up.

Under X, select the second option to customize the values and replace -10.4 with -4 and 10.4 with 4. Click OK, and the graph will update itself automatically.

Other changes can be made in very similar ways. Try and change the line and axes styles.

Another useful feature of the smartplot  is drag-and-drop plotting.

Suppose a first smartplot  (of sin(x) ) has been generated.  Then, execute

>    cos(x);

cos(x)

>   

Select the blue output of this command then drag it and drop it onto the smartplot  of sin(x) .  A graph of cos(x)  will apprear in the smartplot .

The smartplot  can also be launched interactively, via the context-sensitive menu.  Enter and execute

>    sin(x);

sin(x)

>   

Select all the blue output and right-click on it.  The context-sensitive pop-up menu gives the option Plots which leads to 2-D Plot, which, if selected, launches a smartplot  of sin(x) .

>   

Using the interactive  command

The interactive  command is part of the plots  package. It allows you to build plots interactively by opening a window where you can specify details.

For example, to graph f(x) = sin(x)+1  using the interactive  command, type and execute:

>    interactive(sin(x)+1);

Initializing Java runtime environment.

>   

Select 2-D Plot and click Next.

This will open the 2-D Plot window. After entering in your preferences, click Plot. This will display the graph of sin(x)+1 .

Try different options for line style, axes, or color as well.

The interactive plot builder can also be launched interactively, by typing and entering

>    sin(x);

sin(x)

>   

then selecting, and right-clicking on the blue output.  Choose Plots and Plot Builder from the pop-up context-sensitive menu, and the interactive plot-builder will launch.

>   

>