MATH 163, Spring 2001 Due Date: Name(s): Project 0.2: Functions of a Single Variable and Graphing Objective In this project you will learn how to define and graph functions in Maple. Narrative In Maple, the function f = f(x) is defined by the command: f := x -> and we can use the command: plot(f(x),x=a..b) to plot the function f from x = a to x = b plot(f(x),x=a..b,y=c..d) to plot the function f from x = a to x = b, limiting output to points with y-coordinates between c and d plot({f(x),g(x)},x=a..b,y=c..d) to plot functions f and g from x = a to x = b, restricting output to points with y-coordinates between c and d Task a) Type the command lines in the left-hand column below into Maple in the order in which they are listed. The effect of each command is described in the right-hand column for your reference, along with some questions you should ask yourself. > # Project 0.2: Functions of a Single Variable and Graphing > restart; Clear Maple's memory. > f := x -> abs(x^2-4)-2*x; Let f(x) = |x2 - 4| - 2x. > f(3); Evaluate f at x = 3. > plot(f(x),x=-50..50); Plot f from x = -50 to x = 50. (What does this graph tell you about the behavior of f?) > plot(f(x),x=-1..1); Plot f from x = -1 to x = 1. (What does this graph tell you about the behavior of f? It's not so clear anymore, is it?! How do you reconcile this graph with your earlier one? Well, ...) > plot(f(x),x=-4..4); Plot f(x) from x = -4 to x = 4. The point here is that the choice of x-values makes a big difference in getting a good plot of the graph of a function. The following command lines illustrate that the same thing is true for the choice of the y-values. Continue by typing them into Maple in the order in which they are listed. > plot(tan(x),x=-Pi..Pi); Plot tan(x) from x = - to x = . (Does this look like the graph of tan x?) > plot(tan(x),x=-Pi..Pi,y=-3..3); Plot tan(x) from x = - to x = , restricting output to points with y-coordinates between -3 and 3. (We get a much better graph by restricting y-coordinates, but now we have different scales on the x- and y-axes.) In summary, Maple is very useful for graphing, but you cannot trust it completely: it might not reveal important behavior of a function or provide a good picture of a function if you look at a graph of the function at the wrong scale. b) Continue by typing the command line below into Maple. It illustrates how we can plot more than one function in one graphic. > plot({x,2*sin(x)},x=-Pi..Pi); Graph f(x) = x and g(x) = 2 sin x from x = - to x = in one graphic. We will now graphically find the coordinates of the point P(x, y) of intersection of these graphs for which x > 0, in effect finding one of the solutions of x = 2 sin x. Looking at our graph we observe that the correct x value lies between 1.8 and 2.0; so we graph both functions over this interval: continue by typing the following command line into Maple. > plot({x,2*sin(x)},x=1.8..2.0); Plot the graphs of f(x) = x and g(x) = 2 sin x from x = 1.8 to x = 2.0. From this graph it appears that the correct value of x lies between 1.89 and 1.90. So we graph both functions over this interval: continue by typing the following command line into Maple. > plot({x,2*sin(x)},x=1.89..1.90); Replot f(x) and g(x) from x = 1.89 to x = 1.90. From this graph it appears that the correct value of x lies between 1.895 and 1.896. By continuing this process of "zooming in", we could arrive at an arbitrarily precise estimate of the correct x-value. Instead of doing this, however, at this point, make a hard-copy of your typed input and Maple's responses. Then, in each of the last three graphics, label by hand the graphs of f(x) = x and g(x) = 2 sin x by "f(x) = x" and "g(x) = 2 sin x", respectively. Comments 1. Note that when using a function such as sin x in Maple you must type sin(x) (being careful to include parentheses) rather than sin x (which you might write by hand). 2. Maple allows the user to control numerous aspects of the appearance of graphics via "options". For example, to draw the graph of the function f from x = a to x = b in green (rather than in the default color of red), we would use the command plot(f(x),x=a..b,color=green) While there are many advantages to using different colors when viewing a graphic, one potential disadvantage is that they do not always come out well when you print them. Since this issue is hardware dependent, you are advised to try the code as written in future projects; if, however, your graphics do not come out well when you print them, you are advised to use (or change to) an option such as color=black to get a good printed copy. 3. Another way to solve the equation x = 2 sin x is to solve the equation x - 2 sin x = 0 by "zooming in" on the zero of the function h(x) = x - 2 sin x. 4. Observe that the more you "zoom in" on the graph of g(x) = 2 sin x, the more linear it appears. Do you think this is true for all functions? 5. Even though the graphs of curves may appear to be smooth, the way programs like Maple graph functions is by plotting a finite number of points and "connecting-the-dots" with short line segments. Thus, rather than seeing a smooth curve when you plot a function such as sin x, you are actually seeing a polygonal approximation to its graph. This may be why you see vertical lines in the graph of tan x: if x is an odd multiple of /2 then tan x is undefined, but -- unaware of this -- Maple goes ahead and draws a line segment (from a point a little to the left of x to a point a little to the right of x), and that segment is exactly what you see when you see the vertical lines. (To see the dots that Maple uses to graph f, enter the command plot(f(x),x=a..b,style=point).) 6. To specify a piecewise-defined function such as f(x) = x2 if x 0 2x + 1 if 0 < x 1 -2x if x > 1 in Maple you may use: f := x -> if x <= 0 then x^2 elif x <= 1 then 2*x+1 else -2*x fi; In addition to the if/then/elif/else/fi control structure, Maple offers many other structures; to learn more about them, check out the Programming section of Maple's Help. You may also use the piecewise command: to use this command to define the function f above, we write piecewise(x<=0, x^2, x>0 and x<=1, 2*x+1, x>1, -2*x); To learn more about the piecewise command, again check out Maple's Help.