0105.mws
Module 1 : Algebra
105 : Graphs - Seeing & Believing
O B J E C T I V E
The objective of this module is to learn to create graphs in Maple, learn some of the options which can make graphs more interesting and informative, and how to create graphs of multiple functions at once. We will also learn about lines and slope, and how parameters in a function can affect the placement of the graph, that will be helpful later when you need to graph on your own without using Maple.
S E T U P
In this project we will use the following command packages. Type and execute this line before beginning the project below. If you re-enter the worksheet for this project, be sure to re-execute this statement before jumping to any point in the worksheet.
>
restart; with(plots):
___________________________________________________________________________________
A. Basic Graphs
___________________________________________________________________________________
The plot command will graph a function.You must specify a function (no y, just a formula in x) and a domain (the range of values to use for x). Maple will automatically compute the range (y range) to fit the graph.
>
plot(x^2, x=-3..3);
You can also define a function first, then plot it.
>
f:=x-> 9-x^2;
>
plot(f(x), x=-3..3);
A1. Graph y = 2x + 3 using a domain of x = -5..5
A2. Graph the following using domains of your own choice
A.
B. sqrt ( x- 1) C.
(Domain = [-4,11])
A3. A. Define the function f(x) =
B. Experiment with different domains until you can create a graph with the smallest domain that shows all three of this functions x intercepts. Hint start with x = -20..20, then shorten the interval on both sides using integer values until you can't shorten the interval any more without losing sight of an x-intercept.
___________________________________________________________________________________
B. Graphing Options
___________________________________________________________________________________
There are a number of options which can be used to enhance your graphs and make them more sophisticated.
STYLISTIC OPTIONS
There are a number of options which can be used to enhance your graphs. These options can be supplied in any order after the domain (and range) are specified.
Line Thickness
The default thickness is 1 which sometimes results in a graph that is somewhat thin and hard to see for lighter colors. Larger numbers make thicker graphs.
Color of the Curve
Maple chooses colors for the graph on its own unless we specify a color. The 25 colors available are 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
Line Style
Line styles create dashed and dotted graphs. The default value is 1 if you dont specify a linestyle and creates a standard connected graph.
>
plot( 9- x^2, x = -3..3, thickness = 2, color = blue, linestyle = 2);
>
plot( x^3 - 2*x, x = -3..3, thickness = 3, color = gold, linestyle = 3);
>
VERTICAL RANGE
Maple computes the range of y values to use in a graph automatically. However sometimes the results are not what we expect.
The problem here is that the values of the function get very large near x = 1 and so Maple needs to make the y range very large.
>
plot( 1/(x-1), x = -5..5);
At such a large range, we lose the finer detail. We can fix this problem by defining the y-range for ourselves.
The y range is given, after the x range, as two numbers separated by 2 dots - just as the plot domains is defined for x.
>
plot( 1/(x-1), x = -5..5, y = -5..5);
DISCONTINUOUS GRAPHS
The graph above has a flaw. There appears to be a vertical line at x = 1 when really the function is not defined at x = 1. This happens because Maple assumes graphs are continuous, which means there are no breaks or gaps in a smooth curve. So it tries to keep the graph connected by drawing that extra line. We can fix this problem by telling Maple to expect discontinuities.
>
plot( 1/(x-1), x = -5..5, y = -5..5, discont = true);
Another example of a function which has breaks is the greatest integer function, which Maple calls the floor function.
Note the difference in the graphs when you alert Maple that the function has discontinuities.
>
plot( floor(x), x = -5..5, thickness = 3);
>
plot( floor(x), x = -5..5, thickness = 3, discont =true);
MULTIPLE GRAPHS
You can plot several graphs on the same set of axes by enclosing the functions in set braces.
>
plot( {x^2 - 9, 9 - x^2 }, x= -5..5, thickness = 2, color = [blue,green]);
Here is a way of graphing a family of functioins all at once.
B1. Graph the functions x^3, x^3 - 2*x, x^3 + 2*x on the same axes using domain x =-2..2
This single command prints the functions x, x^2, x^3, ..., x^20 on the same set of axes.
Prototype using parameter k.......$ : separates prototype from range....... 1..20 : range of values for the parameter
>
plot( { x^k $ k = 1..20 }, x = 0..1);
>
f := x -> x^2;
>
plot( {f(x - k) $ k = -5..5}, x = -10..10, y = -15..15 );
>
plot( {f(x) - k $ k = -5..5 } , x= -10..10, y = -15..15 );
B2. Copy and paste the three commands above, change f(x) as follows, and re-execute. What can you conclude by these examples?
A. f(x) = | x | (hint : abs) B. f(x) =
C. f(x) = sqrt(x) D. f(x) =
OTHER GRAPH OPTIONS
There are quite a few options available. You can see them all by typing this
>
?plot[options]
Also you can click on any graph and buttons will appear on the toolbar which alter the graph. By clicking on these buttons you can affect the appearance of the graph in some ways.
___________________________________________________________________________________
C. Slope
___________________________________________________________________________________
Every non-vertical line has a slope. What exactly do lines with large and small positive and negative slopes look like? Using the powerful graphing capabilities of Maple, we can see at a glance what lines with different slopes look like. Here are the lines y = x, y = 2x, y = 3x, ..., y = 20x
>
plot({ k*x $ k = 1..20 }, x = -5..5, y = -5..5);
Here is a more sophisticated plot. To create additional lines without executing use shift return (Windows) and return (Macintosh).
>
plots[display]( plot( { k*x $ k = 1..15 }, x = -5..5, y = -5..5, color = blue),
plot( { (1/k)*x $ k = 1..15 }, x = -5..5, y = -5..5, color = green),
plot( { (-1/k)*x $ k = 1..15 }, x = -5..5, y = -5..5, color = gold),
plot( { -k*x $ k = 1..15 }, x = -5..5, y = -5..5, color = red) );
The blue lines have positive integer slopes 1,2,3, ...,15. The green lines have positive fractional slopes of 1/2, 1/3, 1/4, ..., 1/15. The gold lines have negative fractional slopes of -1/2, -1/3, -1/4, ..., -1/15. The blue lines have negative integer slopes -1,-2,-3, ...,-15.
___________________________________________________________________________________
D. Graphing Lines
___________________________________________________________________________________
The equations for lines come in various formats such as the slope-intercept form, the point-slope form, and the standard form. When use the plot command, we need to write the function as a formula in x. For a line, this means we need to express the line in slope-intercept form (y = mx + b) without the y.
>
plot( 3*x + 7, x= -5..5);
There are other ways to express the formulae for lines which do not fit this format such as the point slope form ( y - y1 = m(x- x1) ) or the standard form (Ax + By = C). One option is to use the solve command to convert other forms to slope-intercept form, as we saw in an earlier project.
>
14*x - 7*y = 18;
>
solve( %, y);
However, we can plot these lines directly using a different command.
Note that you must specifiy both an X range and Y range when using this command.
>
plots[implicitplot]( 14*x - 7*y = 18, x = -5..5, y = -5..5);
D1. Graph the following lines using the implicitplot command as shown above.
A. 7*x + 20*y = -13 B. (y-1) = .3*(x + 2) C. 10 - 3x - 4y = 0
___________________________________________________________________________________
E. Shifting Up / Down & Left / Right
___________________________________________________________________________________
Its interesting to see at a glance how changing a function, changes its graph. Here we look at a basic parabola y = x^2. Then consider what happens when we change it to y = (x-k)^2 and y = x^2 + k. To type multiple lines at the same prompt use shift-return on Windows, and return (not enter) on Macintosh.
>
restart; with(plots):
Warning, the name changecoords has been redefined
>
f := x -> x^2;
>
display( plot( f(x) , x = -6..6, y = 0..4, color = green, thickness = 2),
plot( { f(x-k) $ k = 1..4 }, x = -6..6, y = 0..4, color = blue ),
plot( { f(x+k) $ k = 1..4 }, x = -6..6, y = 0..4, color = red),
scaling = constrained );
The original function is in green. The blue curves indicate what happens when k is positive, and the red ones indicate what happens when k is negative.
Now we consider what effect adding or subtracting k from f(x) has on the graph.
>
display( plot( f(x) , x = -6..6, y = 0..4, color = green, thickness = 2 ),
plot( { f(x) - k $ k = 1..4 }, x = -6..6, y = -4..7, color = blue ),
plot( { f(x) + k $ k = 1..4 }, x = -6..6, y = -4..7, color = red),
scaling = constrained );
Again, the original function is in green. You can see that when k is added, the blue graphs result, and when k is subtracted the red curves result.
E1. . Copy and paste the commands above, change the function, and execute the commands
A. f:= x -> abs(x); B. f:= x -> -x^2; C. f := x -> x^3 ; D. f:= x -> (x^2)/(1 + x^2);
___________________________________________________________________________________
F. Parabolas
___________________________________________________________________________________
Every parabola has a vertex and axis of symmetry. With these commands you will see these features on the graph with the parabola.
>
a := 2; b := 3;
display( plot( (x-a)^2 + b, x = -7..7,y = -10..10,thickness = 2, color = green),
plot( [[a,-10],[a,10]], x = -7..7, y = -10..10, color = navy, linestyle = 3),
plot( b, x=-7..7, color = gold, linestyle= 3),
plot( {[a,b]}, x=-7..7, color = red, style=point));
The graph of the parabola is green. The axis of symmetry is the dark blue vertical line. The vertex of the parabola is identified by a small red diamond where the horizontal and vertical lines cross.
F1. Copy and paste the block of commands above. Change the values of a and b and execute the block.
A. a := -2, b := 3 B. a := 2, b := -3 C. a := -4, b := -4
F2. Use the fact that the vertex of
is (a,b) and the commands above to graph the parabola along with its vertex and axis of symmetry.
A.
B.
>