! ITERATION OF SQUARE ROOT EQUATION
SET MODE "graphics"
!Creates a full screen output window
SET WINDOW -.2*1.33,2.2*1.33,-.2,2.2
!Defines a sligthly larger than 2 by 2 square window.
BOX LINES 0,2,0,2
!Draws a 2 by 2 box
!Draws the 45 degrees diagonal (y=x)
!Draws the lines defining the coordinates of point (1,1)
PLOT TEXT, AT .9,1.05: "(1,1)"
!Writes the name (1,1) near that point.
SET COLOR "red"
PLOT TEXT, AT 1.7,1.2: "y=sqr(x)"
!Labels in red the plot of the function square root.
SET COLOR "black"
PLOT TEXT, AT 1.6,1.7: "y=x"
!Labels in black the plot of the function y=x.
FOR x= 0 to 2 step 0.01
LET xn= SQR(x)
SET COLOR "red"
PLOT x, xn;
!This FOR-NEXT loop plots in red the function y=sqr(x) for x between 0 and 2.
!Here starts a DO-LOOP that does the graphical iteration: clicking in the output
!window selects the starting point; different cases (strating points) are plotted
!with different colors for clarity.
IF j=0 THEN SET COLOR "black"
LET j = j+1
IF j=1 THEN SET COLOR "brown"
IF j=2 THEN SET COLOR "red"
IF j=3 THEN SET COLOR "blue"
IF j=4 THEN SET COLOR "green"
IF j>4 THEN SET COLOR "black"
!Notice that after 4 cases black is used; ! graph would look too crowded anyway if j>>4.
!This PLOT "empty" command allows to interrupt the"connect the points"
!created by the "; " feature, so that the next case starts "fresh".
GET POINT x0,y0
!This GET POINT command allows mouse selection of the starting point x0.
!Notice that y0 is not used.
PRINT "x0 is: ";x0
PLOT TEXT, AT x0,-.1 :"x0"
!The selected point is recorded at the top and identified in the x axis.
!Notice that the x0 values are also color coded.
!This FOR-NEXT LOOP does the graphical iteration:
FOR i=1 to 10
!Do ten steps of the graphical iterations
LET x1= SQR(x0)
!Calculates the ordinate of x0.
!Plots the line connecting the point in the curve y=sqr(x0) with the point in y=x
!Allow a short pause to see the build-up of the iteration.
!Use the next value as a seed and repeat.
!This creates the "stepwise" look of the iteration.
!Once the 10 steps are done, get ready to accept a new input value for x0.
!This LOOP instruction closes the DO loop.
!This program will run "forever" unless STOP is used to terminate.