<?xml version="1.0" encoding="UTF-8"?>
<Worksheet><Version major="6" minor="1"/><View-Properties><Zoom percentage="100"/></View-Properties><Styles><Layout alignment="left" bullet="none" linespacing="0.0" name="Heading 1" spaceabove="8.0" spacebelow="4.0"/><Layout alignment="left" bullet="none" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Normal" rightmargin="0.0" spaceabove="0.0" spacebelow="0.0"/><Font background="[0,0,0]" bold="true" executable="true" family="Monospaced" foreground="[255,0,0]" name="Maple Input" opaque="false" size="12"/><Font background="[0,0,0]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Text" opaque="false" size="12" underline="false"/><Font background="[0,0,0]" bold="true" family="Serif" name="Heading 1" opaque="false" size="18"/></Styles><Group><Input><Text-field alignment="centred" firstindent="0.0" layout="Heading 1" leftmargin="0.0" linebreak="space" rightmargin="0.0" style="Heading 1"><Font executable="false" foreground="[0,0,0]" italic="false" underline="false">Introduction to Cobweb Diagrams</Font></Text-field><Text-field layout="Normal" style="Text">This worksheet is intended to help you understand where cobweb diagrams come from and how they are interpreted.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">restart;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Consider the iteration map given by the following function:</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">f := x -&gt; 100-0.7*(x-100);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let's create a sequence of 50 iterates. Note the use of the colon (:) to avoid printing all 50 calculation results.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">N := 50;
p[0] := 10;
for t from 1 to N do p[t] := f(p[t-1]); end do:</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">First, let's just look at the data as a time sequence.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">with (plots):
listplot( [ seq([t,p[t]], t=0..N) ], style=POINT);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Next, let's consider the single-lag plot, comparing sequential generations.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">listplot( [ seq([p[t-1],p[t]], t=1..N) ], style=POINT,
	labels=["p[t]","p[t+1] "],
	labeldirections=[HORIZONTAL, VERTICAL]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">These data points obviously fall on a line. What line is it?</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Remember how p[t+1] is defined by the iteration. That is, p[t+1] = f(p[t]). That is, the ordered pair (p[t],p[t+1]) is the same as the ordered pair (p[t], f(p[t]), which is just one point on the graph of f(x).</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Let's plot f(x). We use the Maple command plot.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot(f(x), x=0..200, y=0..200);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Of course, this is also a line. But is it the same line? We can tell Maple to join to plots if we define objects for each of the plots:</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">dataPlot := listplot( [ seq([p[t-1],p[t]], t=1..N) ], style=POINT);
fcnPlot := plot(f(x), x=0..200, y=0..200);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Okay, that doesn't look like a plot. Whenever you define an object to contain information about a plot, it no longer appears as a plot but shows you how Maple is describing the plot. We hide the output by changing the semicolon to a colon:</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">dataPlot := listplot( [ seq([p[t-1],p[t]], t=1..N) ], style=POINT):
fcnPlot := plot(f(x), x=0..200, y=0..200):</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Once the plot objects are defined, we display them using the plots[displayplot] command.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">display([dataPlot,fcnPlot],
	labels=["p[t]","p[t+1]=f(p[t]) "],
	labeldirections=[HORIZONTAL,VERTICAL]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Great!</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">We can now clearly see that the sequential generation data points are clearly on the graph of f(x).</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text"><Font bold="true">Challenge question</Font>: If you change the lag to 2 generations, the data will belong to the graph of which function?</Text-field><Text-field layout="Normal" style="Text"/></Input></Group><Group><Input><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Okay. Now we turn to the idea of cobweb diagrams. A cobweb diagram is a graphical approach to generating the time sequence that is motivated by our earlier observation that sequential generation data appears on the graph of the iteration function f(x).</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Before we actually talk about the cobweb diagram, let's keep thinking about the graph and the order in which the points appear.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">So, we start with the graph of the function:</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">display(fcnPlot);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">With this plot, we use our initial condition, and plot the vertical line x=p[0]. The point of intersection of the graph of f(x) and the vertical line is the point (p[0], f(p[0])).</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">vertLine[0] := listplot([ [p[0],0], [p[0],200] ], style=LINE):
intersectPt[0] := listplot( [ [p[0],f(p[0])] ], style=POINT):
display([fcnPlot, vertLine[0], intersectPt[0]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">The height of this point is the size of the population in the first generation. We can test the truth of the equation with the evalb (evaluate a boolean) command.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">evalb(p[1] = f(p[0]));</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">We can do the same thing with the next time point.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">vertLine[1] := listplot([ [p[1],0], [p[1],200] ], style=LINE):
intersectPt[1] := listplot( [ [p[1],f(p[1])] ], style=POINT):
display([fcnPlot, vertLine[0], intersectPt[0], vertLine[1], intersectPt[1]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Notice that the height of the first point is the same as the position of the second line. Let's repeat this one more time. Let's plot the vertical line at x=p[2].</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">vertLine[2] := listplot([ [p[2],0], [p[2],200] ], style=LINE):
intersectPt[2] := listplot( [ [p[2],f(p[2])] ], style=POINT):
display([fcnPlot, vertLine[0], intersectPt[0], vertLine[1], intersectPt[1],
	vertLine[2], intersectPt[2]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Now, you should be able to predict on your own where the next point will appear. Make your prediction before you try the next command.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">vertLine[3] := listplot([ [p[3],0], [p[3],200] ], style=LINE):
intersectPt[3] := listplot( [ [p[3],f(p[3])] ], style=POINT):
display([fcnPlot, vertLine[0], intersectPt[0], vertLine[1], intersectPt[1],
	vertLine[2], intersectPt[2], vertLine[3], intersectPt[3]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">How did you do?</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Okay, now, let's go back to the first two lines.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">display([fcnPlot, vertLine[0], intersectPt[0], vertLine[1], intersectPt[1]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">I'm going to add a horizontal line connecting the first line that goes over to the second line.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">horizLine[0] := listplot( [ [p[0],f(p[0])], [p[1], f(p[0])] ], style=LINE):
display([fcnPlot, vertLine[0], intersectPt[0],
	horizLine[0], vertLine[1], intersectPt[1]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Well, the question is now, if I didn't already know where the second line was, how would I know how far over to draw the line?</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Let's think...

The first line is at the position x=p[0], and the second line is at the position x=p[1]. The height of the horizontal line is at y=f(p[0]). But this is the same as y=p[1] since p[1]=f(p[0]). That is, the horizontal line ends when it reaches the point (p[1],p[1]).</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">What if we continue? Let's include the third vertical line again.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">horizLine[1] := listplot( [ [p[1],f(p[1])], [p[2], f(p[1])] ], style=LINE):
display([fcnPlot, vertLine[0], intersectPt[0],
	horizLine[0], vertLine[1], intersectPt[1],
	horizLine[1], vertLine[2], intersectPt[2]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">The second horizontal line starts at (p[1], f(p[1])) and joins the point (p[2], f(p[1])). What is this end point? By the same reasons as above, it is the point (p[2],p[2]). In fact, if we continued this process, drawing a horizontal line between consecutive vertical lines, then it will end when it intersects the line y=x.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">identityPlot := plot(x, x=0..200,y=0..200, color=blue):
display([fcnPlot, identityPlot,
	vertLine[0], intersectPt[0],
	horizLine[0], vertLine[1], intersectPt[1],
	horizLine[1], vertLine[2], intersectPt[2]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let's do this again. Based on the pattern we've seen, what is the next value for the population?</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">horizLine[2] := listplot( [ [p[2],f(p[2])], [p[3], f(p[2])] ], style=LINE):
display([fcnPlot, identityPlot,
	vertLine[0], intersectPt[0],
	horizLine[0], vertLine[1], intersectPt[1],
	horizLine[1], vertLine[2], intersectPt[2],
	horizLine[2], vertLine[3], intersectPt[3]]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Looking at this graph, the vertical lines clutter our diagram, so we only draw the parts that contribute to finding the next point.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">We finally reach a true cobweb diagram.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">vertLine[0] := listplot( [ [p[0],0], [p[0],f(p[0])] ], style=LINE ):
for t from 1 to N do
	horizLine[t] := listplot( [ [p[t-1],p[t]], [p[t],p[t]] ], style=LINE);
	vertLine[t] := listplot( [ [p[t],p[t]], [p[t], f(p[t])] ], style=LINE);
end do:
display([ dataPlot, fcnPlot, identityPlot, 
	seq( vertLine[t], t=0..N ),
	seq( horizLine[t], t=1..N) ]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">A cobweb diagram: 
(1) Start with a graph of the function y=f(x). Also draw the graph of the identity function, y=x.
(2) Take an initial condition, and find the corresponding x-position.</Text-field><Text-field layout="Normal" style="Text">(3) Move vertically to the graph of f(x). The height is the next population size.</Text-field><Text-field layout="Normal" style="Text">(4) Move horizontally to the graph of y=x. The new x-position is the new population size</Text-field><Text-field layout="Normal" style="Text">(5) Treat this x-value as a new initial condition and repeat step (3) and (4).</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">With Maple, we can actually get this to animate so that we can visualize it a little better.

First we define a function that draws the cobweb diagram through a certain number of iterations:</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">cobweb := n -&gt; display([ dataPlot, fcnPlot, identityPlot,
	seq( vertLine[t], t=0..ceil(n) ), seq( horizLine[t], t=1..ceil(n) )]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Now try a few of these:</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">cobweb(1);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">cobweb(2);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">cobweb(3);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Now we'll use the plots[animate] routine to make a movie.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" prompt="&gt; " style="Maple Input">animate(cobweb, [n], n=0..12, frames=13);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Text-field/></Worksheet>