Cobweb Diagrams
| > |
 |
First input the function you wish to iterate.
| > |
 |
Next, input the starting value for x[0].
| > |
![`:=`(x[0], .95); -1](images_cob/cobwebs_3.gif) |
Input the desired number of steps.
| > |
 |
Finally, input the interval you want the iteration function to be defined over, with left endpoint
a and right endpoint b.
| > |
 |
| > |
 |
The next five lines draw the first line of the
"cobweb graph," the graph of the function f(x) and the diagonal line.
| > |
![`:=`(v, [[x[0], 0], [x[0], f(x[0])]]); -1](images_cob/cobwebs_8.gif) |
| > |
 |
| > |
 |
| > |
 |
| > |
![`:=`(frame0, display([diagonal, graph, step0])); -1](images_cob/cobwebs_12.gif) |
The following loop will calculate x[1] = f(x[0]), x[2] = f(x[1]), etc. It will also create the graphics
for the cobweb diagram.
| > |
for k from 1 to numsteps |
| > |
x[k] := evalf(f(x[k-1]),20): |
| > |
if x[k]<a or x[k]>b then v:=[op(v),[x[k-1],f(x[k-1])]] else v:= [ op(v), [x[k], x[k]], [ x[k], f(x[k]) ] ] fi: |
| > |
if x[k]<a or x[k]>b then numsteps:=k-1 else step||k:=plot(v, x = a..b, color=black) fi: |
| > |
if x[k]<a or x[k]>b then numsteps:=k-1 else frame||k:=display([step||k, diagonal, graph]) fi: |
| > |
if x[k]<a or x[k]>b then break fi: |
The following line puts the various stages into film so you can view an animated version
of the procedure.
| > |
![`:=`(film, [seq(frame || k, k = 0 .. numsteps)]); -1](images_cob/cobwebs_13.gif) |
Finally, to view an animation of the cobweb graph, execute the following line, then click
on the graph. Play the film using the playback toolbar that appears at the top of the screen.
| > |
 |