<table><tr><td width=200 valign=top> <p> <img src=../../home/home_page/home.jpg width=170 height=240> <br>Robert John Morton <p>About my interest in: <h3>Chaos Theory</h3> <p> <a href=../intro/intro_frame.htm>Introduction</a><br> <a href=../difeqn/difeqn_frame.htm>Difference Equation</a><br> <a href=../bifmap/bifmap_frame.htm>Bifurcation Maps</a><br> <a href=../mandel/mandel_frame.htm>Mandelbrot Set</a><br> <a href=../henon/henon_frame.htm>H&eacute;non's Attractor</a><br> <a href=../feig/feig_frame.htm>Iterative Function</a><br> <a href=../lissajou/lissajou_frame.htm>Lissajou's Figures</a> <p><a href=../../index.htm>Home Page/Email</a> <p><a href=../intro/intro_br_frame.htm> <img src=../../images/brazil.gif width=48 height=31 border=0></a> <br>Clique na bandeira<br>para ler em Português. <td> <h3>Chaos Theory: <big>Iterative Sine Wave Generator</big></h3> <blockquote><p align=justify><i> This program is written in Basic. Cut and paste it into a Basic 'workbench' such as Microsoft QuickBasic. Then compile it and run it. It generates the sine wave by iterating a simple difference equation. It displays the sine wave, as it is being generated, both as an amplitude-time graph and as a phase diagram.</i> [<a href=feig_br_frame.htm target=_top>Português</a>] [<a href=../../articles-pdf/difference_equation_program_sine_wave_BASIC.pdf target=_blank>PDF</a>] </p></blockquote> <pre><code> 'SINE-WAVE DIFFERENCE FUNCTION screen 9,3 color 7,1 th = 3 'text horizontal bias s = 1.5 'horizontal scaling factor n = 150 'integral extent of the axes h = 230 'horizontal zero bias v = 330 'vertical zero bias nn = 550 'extent of time-series horizontal axis hh = 25 'time-series horizontal bias vv = 160 'time-series vertical bias ss = 200 'inter-iteration delay 'DISPLAY THE RUN INFORMATION locate 14, th : print"Difference-generated sine function" locate 23, th : print"Press any key to stop program." locate 19, th : print"yMAX =" locate 20, th : print"yMIN =" 'DRAW AXES FOR THE TIME-SERIES DIAGRAM ts = 1 'set time-series flag c = 3 'set colour to cyan for axes t = nn : x = 0 : gosub p 'set pen to end of time axis t = 0 : gosub l 'draw line to time-series origin x = 1 : gosub l 'draw time-series y-axis locate 2, 3 : print "y" locate 12, 74 : print "time" 'DRAW THE GRAPH AXES FOR THE PHASE DIAGRAM ts = 0 'clear time-series flag x = 1 : y = 0 : gosub p 'set pen to end of x-axis x = 0 : gosub l 'draw line to origin y = 1 : gosub l 'continue line to end of y-axis locate 14, 43 : print "y" locate 24, 73 : print "x"; 'ITERATE NON-LINEAR DIFFERENCE FUNCTION UNTIL A KEY IS PRESSED oldx = 0 t = 1 'initialise the time u = 61 'start of trace-clearing sweep ymax = 0 'holds maximum excursion of y ymin = 1 'holds minimum excursion of y sx = -1 'set initial value of input sy = 0 'for position of first plot gosub p 'set plotting pen to starting value e = 0 'reset the out-of-range flag while inkey\$ = "" 'while user has not pressed a key... gosub p 'set starting point for current line oldx = x gosub f 'ITERATE THE DIFFERENCE FUNCTION newx = x gosub l 'draw line to point x, y gosub TimeSeries 'put plot on time-series graph for tt = 0 to 5000 : next wend : end 'TIMES-SERIES GRAPH PLOTTING ROUTINE TimeSeries: ts = 1 'set time-series flag c = 10 'set trace colour to bright green if t &gt; nn then t = 1 'if end of sweep has been reached x = oldx : gosub p 'set to previous plot position t = t + 5 'increment the time axis x = newx : gosub l 'draw line to current plot if u &gt; nn then u = 1 uu = u + hh : uuu = uu + 10 for i = uu to uuu 'draw the trace-wiper in blue line (i, vv - n) - (i, vv - 1), 1 next u = u + 5 ts = 0 'clear the time-series flag return p: gosub q : pset(a, b), c 'set starting point for current line return l: gosub q : line -(a, b), c 'draw line to point x, y return 'CONVERT REAL X/Y CO-ORD TO SCALED INTEGRAL NUMBERS OF PIXELS q: if ts = 0 then a = s * (h + n * x) b = v - n * y else a = hh + t b = vv - n * x end if return 'ITERATE THE DIFFERENCE FUNCTION f: if sx &lt; 0 then sa = .05 else sa = -.05 sy = sy + sa sx = sx + sy if sy &gt; ymax then ymax = sy : locate 19, th + 8 : gosub num if sy &lt; ymin then ymin = sy : locate 20, th + 8 : gosub num x = sx / 4 + .51 y = sy / 4 + .51 return num: y\$ = str\$(sy) : PRINT y\$ + space\$(13 - len(y\$)) return</code></pre> <hr> &copy; October 1997 Robert John Morton | <a href=../henon/henon_frame.htm target=_top>PREV</a> | <a href=../lissajou/lissajou_frame.htm target=_top>NEXT</a> </table>