Sketching Graphs and Subroutines

advertisement
Sketching Graphs and Subroutines
D. P. Morstad, University of North Dakota
Objectives of Assignment
1.
2.
I.
To learn how to write and use subroutines in X(PLORE).
To practice integrating information about graphs of functions in order to
be able to sketch them.
Introduction
Many of you who worked on Computer Assignment #1 wondered why X(PLORE)
doesn't have a way to graph two or three functions with just one command. It seemed a waste
of time to write "graph(f(x), x)," look at the graph, and then have to go back to the input screen
in order to have the next function graphed.
X(PLORE) actually does have the ability to graph three functions at once (or do any
number of things at once) with just one command, but you have to tell it what things you want it
to do. You tell X(PLORE) to do several things at once by writing a subroutine.
Back in Computer Assignment #1, "mystery1," "mystery2," "salary1," and all those
other things that you typed in for the hand–in assignment were actually subroutines.
II.
The Basics of Subroutines
You are already familiar with X(PLORE)'s input screen and the graphics screen, but
X(PLORE) also has a third screen called a subroutine screen. You can get to the subroutine
screen by pressing ). You also leave the subroutine screen by pressing ).
To write a subroutine in the subroutine screen, you need to do three things:
U
U
U
Name the subroutine.
Write all the commands you want X(PLORE) to do at once.
End the subroutine.
Once you have written a subroutine, X(PLORE) can use it at any time. To make
X(PLORE) run your subroutine, just enter the name of the subroutine on the input screen.
30
Notice that you type in the subroutine on the subroutine screen, but you run the subroutine from
the input screen.
III.
Two Examples of Subroutines
First is a subroutine which will graph three functions at once, followed by an explanation
of each line. The indenting is not necessary, it just helps visualize structure.
Procedure graph3(%f, %g, %h)
Graphics
graph(f(x), x)
graph(g(x), x)
graph(h(x), x)
Text
end
LINE 1:
The word Procedure tells X(PLORE) that you are naming and writing a
subroutine (procedure is a synonym for subroutine). Graph3 is the name of this
subroutine. Inside the parentheses, %f, %g, and %h are the names of what you want
X(PLORE) to work with when it is running this subroutine. The percentage signs are
secret code that tells X(PLORE) these are three functions instead of just three variables.
Notice that it is simply %f, not %f(x).
LINE 2:
The word Graphics tells X(PLORE) to execute all the lines without stopping
after each line. It really has nothing to do with the fact that you will be doing some
graphing. Without Graphics, X(PLORE) would just execute one line and wait until you
pressed E before executing the next line.
LINES 3, 4, 5: The three lines in the middle tell X(PLORE) to graph each function. Before
you use this subroutine, you will want to define a graphing window and your three
functions on the input screen.
LINE 6:
The word Text is a companion to Graphics. It tells the computer to stop
executing line after line without stopping. X(PLORE) is set up so that whenever
Graphics is in a subroutine, Text must also appear later.
LINE 7:
The word End signals the end of the subroutine. Other subroutines can be
written in the subroutine screen after End. X(PLORE) subroutines must have End at
the end.
Try this subroutine. Press ) to get to the subroutine screen, type in the seven lines,
and then press ) to get back to the input screen. When you are back at the input screen,
define a graphing window, type in any three functions you want, and then type
31
graph3(f(x), g(x), h(x)).
At this point, you must include the variables in the functions, but do not use "%". Also,
the letters you use to identify the functions you want graphed must match the letters you used to
define them in the input window, but they do not have to match the letters you used inside the
subroutine screen.
Next is a simple example of a subroutine that will let you define a window and graph a
function, all with one command.
Procedure graphwin(%f, xl, xr, yb, yt)
Graphics
window(xl, xr, yb, yt)
graph(f(x), x)
Text
End
In this procedure, the variable names xl, xr, yb, and yt stand for the x–left, x–right, y–
bottom, and y–top of the graphing window. X(PLORE) knows these are not funtions because
they have no % infront of them. Again, %f represents the function you want to pass into the
subroutine.
If you press ) and type in this subroutine, you do not need to eliminate the other
subroutine from the subroutine screen. X(PLORE) keeps them separate and distinct as long as
each one has the word End at its end.
After typing in this subroutine and then getting back to the input screen, define any
function you want. You will be able to define a window and graph the function all in one step
by typing:
graphwin(f(x), –3, 4, –5, 6).
Of course, you might want to use a different window.
Subroutines can be used to make X(PLORE) do just about any thing you want it to.
For example, you could modify graph3 to graph in specific colors by just adding the line
color(_______) before each graph(_(x), x) line. You might want to reload assign1.xpl or
assign2.xpl to investigate how those subroutines were written. The manual that came with your
copy of X(PLORE) can also provide lots of additional information and examples of subroutines.
32
IV.
Sketching Graphs of Functions from Information Summaries
For problems 1 and 2 below, use graph3 to graph the functions. Then, by looking at
the graph of each function, find all:
a)
b)
c)
d)
e)
f)
g)
h)
1.
2.
relative minimums,
relative maximums,
intervals where the function is increasing,
intervals where the function is decreasing,
inflection points,
intervals where the function is concave up,
intervals where the function is concave down,
asymptotes of the function.
f ( x ) = x 4 − 2 x 3 − 4 x 2 + 2 x + 3, g ( x ) = x 3 − 3x 2 + 2 x − 1,
4
h( x ) = x + 2 x 3 − 3 x 2 − x + 2
f ( x) =
x
1
3x 2 − 2 x
, g( x ) = 2
, h( x ) = 2
.
x +1
x −4
x −1
For problems 3 – 7, sketch a graph based on the given information summary. Then
have X(PLORE) graph the five functions given after exercise 7. Match your sketches to the
graphs X(PLORE) draws.
3.
Graph A:
a)
relative minimum at: (–1.4, –2.5),
b)
relative maximum at: (0.7, 2.2),
c)
increasing on: (–1.4, 0.7),
d)
decreasing on: (–∞, –1.4), (0.7, ∞),
e)
inflection point at: (–0.39, –0.24),
f)
concave up on: (–∞, –0.39),
g)
concave down on: (–0.39, ∞),
h)
vertical asymptotes at: none,
i)
horizontal asymptote at: none.
4.
Graph B:
a)
relative minimums at: (–1,0) and (2.26, –9.98),
b)
relative maximum at : (0.215, 3.13),
c)
increasing on: (–1, 0.215) and (2.26, ∞),
d)
decreasing on: (–∞, –1), and (0.215, 2.26),
(continued on next page)
33
e)
f)
g)
h)
i)
inflection points at: (–0.5, 1.11) and (1.42, –3.93),
concave up on: (–∞, –0.5) and (1.42, ∞),
concave down on: (–0.5, 1.42),
vertical asymptotes at: none,
horizontal asymptote at: none.
5.
Graph C:
a)
relative minimum at: (0,0),
b)
relative maximums at : none,
c)
increasing on: (0, 1) and (1, ∞),
d)
decreasing on: (–∞, –1) and (–1, 0),
e)
inflection points at: none,
f)
concave up on: (–1, 1),
g)
concave down on: (–∞, –1) and (1, ∞),
h)
vertical asymptotes at: x = –1 and x = 1,
i)
horizontal asymptote at: y = –1.
6.
Graph D:
a)
relative minimums at: none,
b)
relative maximums at : none,
c)
increasing on: nowhere,
d)
decreasing on: (–∞, –1), (–1 ,1), and (1, ∞),
e)
inflection point at: (0, 0),
f)
concave up on: (–1, 0) and (1, ∞),
g)
concave down on: (–∞, –1) and (0, 1),
h)
vertical asymptotes at: x = –1 and x = 1,
i)
horizontal asymptote at: y = 0.
7.
Graph E:
a)
relative minimum at: (–1.7, 2.5),
b)
relative maximum at : (1.7, –2.5),
c)
increasing on: (–1.7, –1), (–1, 1), and (1, 1.7),
d)
decreasing on: (–∞, –1.7) and (1.7, ∞),
e)
inflection point at: (0, 0),
f)
concave up on: (–∞, –1), and (0, 1)
g)
concave down on: (–1, 0) and (1, ∞),
h)
vertical asymptotes at: x = –1 and x = 1,
i)
horizontal asymptote at: none.
On the next page are the functions to be matched with graphs A – E.
34
f1 ( x ) =
− x2
,
x 2 −1
f 2 ( x ) = − x 3 − x 2 + 3x + 1,
f 4( x ) =
x
,
x −1
f 5 ( x ) = x 4 − 2 x 3 − 4 x 2 + 2 x + 3.
2
Answers:
1.
f3 ( x ) =
x3
,
1− x2
(All answers are approximations based on X(PLORE) crosshair values.)
f(x):
a)
b)
c)
d)
e)
f)
g)
h)
i)
relative minimums at: (–0.98, 0.13) and (2.3,–9.8),
relative maximum at : (0.24, 3.22),
increasing on: (–0.98, 0.24) and (2.3, ∞),
decreasing on: (–∞, –0.98) and (0.24, 2.3),
inflection points at: (–0.37, 1.79) and (1.4, –3.7),
concave up on: (–∞, –0.37) and (1.4, ∞),
concave down on: (–0.37, 1.4),
vertical asymptotes at: none,
horizontal asymptotes at: none.
g(x):
a)
b)
c)
d)
e)
f)
g)
h)
i)
relative minimums at: (1.635, –1.580),
relative maximum at : (0.430, –0.572),
increasing on: (–∞, 0.430) and (1.635, ∞),
decreasing on: (0.430, 1.635),
inflection points at: (0.912, –0.908),
concave up on: (0.912, ∞),
concave down on: (–∞, 0.912),
vertical asymptotes at: none,
horizontal asymptotes at: none.
h(x):
a)
b)
c)
d)
e)
f)
g)
h)
i)
relative minimums at: (–2.14, –8.23) and (0.791, 0.713),
relative maximums at : (–0.147, 2.07),
increasing on: (–2.14, –0.147) and (0.791, ∞)
decreasing on: (–∞, –2.14) and (–0.147, 0.791),
inflection points at: (–1.3, –4) and (0.43, 1.109),
concave up on: (–∞, –1.3) and (0.43, ∞),
concave down on: (–1.3, 0.43),
vertical asymptotes at: none,
horizontal asymptote at: none.
35
2.
f(x):
a)
b)
c)
d)
e)
f)
g)
h)
i)
relative minimums at: none,
relative maximums at : none,
increasing on: (–∞, –1) and (–1, ∞),
decreasing on: nowhere,
inflection points at: none,
concave up on: (–∞, –1),
concave down on: (–1, ∞),
vertical asymptote at: x = –1,
horizontal asymptote at: y = 1.
g(x):
a)
b)
c)
d)
e)
f)
g)
h)
i)
relative minimum at: none,
relative maximum at : (0, –.25),
increasing on: (–∞, –2) and (–2, 0),
decreasing on: (0, 2) and (2, ∞),
inflection point at: none,
concave up on: (–∞, –2) and (2, ∞),
concave down on: (–2, 2),
vertical asymptotes at: x = –2 and x = 2,
horizontal asymptote at: y = 0.
h(x):
a)
b)
c)
d)
e)
f)
g)
h)
i)
relative minimums at: none,
relative maximums at : (0.38, 0.38),
increasing on: (–∞, –1) and (–1, 0.38),
decreasing on: (0.38, 1) and (1, ∞),
inflection point at: none,
concave up on: (–∞, –1) and (1, ∞),
concave down on: (–1, 1),
vertical asymptotes at: x = –1 and x = 1,
horizontal asymptote at: y = 0.
3. Graph A is f 2 ( x ). 4. Graph B is f 5 ( x ) .
6. Graph D is f 4 ( x ). 7. Graph E is f 3 ( x ) .
36
5. Graph C is f1 ( x ) .
Download