23 3 78 elu033 gf 5 rem - "graphfunction" - a basic program to graph f(x),automatic scaling 6 rem - floating origin,linear axes (initially - see documentation) 7 rem - Copyright Julian.H.Stacey, Canterbury, 1977 13 print 14 print "into graphfunction - 23/03/78 version" 15 print 16 print "have you entered function ?"; 17 input b$ 18 print 19 if b$ = "yes" then 29 20 if b$ = "y" then 29 21 print "before running program go into command mode and" 22 print "enter functions in lines 33 & 622 as follows :-" 23 print ":33 def fna(x)=your function of x" 24 print ":622 print 'your function'" 25 print "nb p,k,e already defined as 4*arctan(1),log(10),10^(1/k)" 26 print 27 goto 865 29 rem - define pi,log(10),e 30 let p = 4*atn(1) 31 let k = log(10) 32 let e = 10^(1/k) 33 def fna(x) = (exp(-2*x))*(sin(15*x))*(sin(60*x)) 35 rem - parameter input 37 print "input min x, max x, no of graph points, max/easy scaling" 38 print "(typical input : -8,23,35,max)" 39 input x1,x2,n,a$ 40 print 42 if x1 <> x2 then 51 45 print "min x = max x not allowed - reinput min x,max x :-"; 47 input x1,x2 48 print 49 goto 42 51 if n <> 0 then 57 52 print "0 graph points not allowed - reinput number :-"; 53 input n 54 print 55 goto 51 57 rem - select scaling 58 let c1 = 1 59 if a$ = "max" then 73 60 if a$ = "m" then 73 61 let c1 = 0 62 if a$ = "easy" then 73 65 if a$ = "e" then 73 66 print "do you want maximum graphspace utilisation or easy scaling " 67 print "for axis readoff - answer max or easy :-"; 68 input a$ 69 print 70 goto 57 73 rem - prog ensures x2>x1 74 if x2 > x1 then 85 76 let x3 = x2 78 let x2 = x1 80 let x1 = x3 85 let n = 5*int((abs(n)+4)/5) 90 rem input ended 100 rem - find y1,y2 the min,max values of f(x) 105 let y1 = fna(x1) 107 let y2 = fna(x1) 110 for i = 0 to n 115 let y = fna(x1+(x2-x1)*i/n) 120 if y >= y1 then 130 125 let y1 = y 127 goto 150 130 if y <= y2 then 150 135 let y2 = y 150 next i 180 if y1 <> 0 then 200 185 if y2 = 0 then 422 200 rem - find mantissae of y1,y2 (m1,m2) rel to largest exponent e2 235 if abs(y1) < abs(y2) then 250 240 let e2 = int(log(abs(y1))/k)+1 245 goto 260 250 let e2 = int(log(abs(y2))/k)+1 260 let m1 = y1*10^(-e2) 270 let m2 = y2*10^(-e2) 400 rem - find axis limits l1,l2 420 let d = m2-m1 421 if d > 0 then 426 422 print "min f(x) = max f(x) - have you input: f(x)=constant, or" 423 print "numbers beyond computer capability ie f(x)=10^30+sin(x) ?" 424 print 425 goto 865 426 let c = 1 430 if d > 1 then 447 435 let d = 10*d 440 let c = c+1 445 goto 430 447 rem - calculate l1,l2 455 let a = 0 460 let b = 1 465 if y1 >= 0 then 502 470 let a = 1 480 if y2 > 0 then 502 485 let b = 0 502 rem - a & b allow for +ve & -ve graph regions 506 let m1 = abs(m1) 508 let m2 = abs(m2) 515 if m1*10^(1+c1) > int(m1*10^(1+c1))+1?-6 then 525 520 let a = 0 525 let l1 = sgn(y1)*10^(e2-c+1-c1)*(int(m1*10^(c+c1-1))+a) 530 if m2*10^(1+c1) > int(m2*10^(1+c1))+1?-6 then 540 535 let b = 0 540 let l2 = sgn(y2)*10^(e2-c+1-c1)*(int(m2*10^(c+c1-1))+b) 545 rem decide scale factor 547 let d = (l2-l1)*10^(c-e2-2) 554 rem - decide s for max graph size or easy f(x) axis scaling 560 let s = 1/d 565 if a$ = "max" then 590 567 if a$ = "m" then 590 570 let s = 1 575 if d > 0.5 then 590 580 let s = 2 585 if d > 0.2 then 590 587 let s = 5 590 let s = (10^(2-c+e2))/(s*50) 610 rem - s is f(x) units per column tab,l1 is lower end of f(x) axis 615 gosub 1300 616 rem - print graph 620 print "function is "; 622 rem - function for printout on this line 624 print "function on horizontal axis,ordinate on vertical"; 626 print " * & i = h , * & + = x" 627 print 628 print tab(14);l1;tab(24);l1+10*s;tab(34);l1+20*s; 630 print tab(44);l1+30*s;tab(54);l1+40*s;tab(64);l1+50*s 632 print tab(8);"-f(x)<-+---------+---------+---------+"; 635 print "---------+---------+->f(x)" 640 rem - decide whether to plot f(x)=0 in graph,or at edge 645 if l2 <= 0 then 800 650 if l1 > 0 then 800 655 rem - plot f(x)=0 in graph 660 let z = 15-l1/s 665 for i = 0 to n 667 let h = x1+(x2-x1)*i/n 668 let t = 15+((fna(h))-l1)/s 670 let g = i/5-int(i/5) 672 rem - compare tab(function),with tab(zero) 675 if int(t+0.5) > int(z+0.5) then 745 680 if int(t+0.5) = int(z+0.5) then 715 685 rem - f(x)<0 690 if g = 0 then 705 695 print tab(t);"*";tab(z);"i" 700 goto 770 705 print h;tab(t);"*";tab(z);"+" 710 goto 770 715 rem - f(x)=0 720 if g = 0 then 735 725 print tab(z);"h" 730 goto 770 735 print h;tab(z);"x" 740 goto 770 745 rem - f(x)>0 750 if g = 0 then 765 755 print tab(z);"i";tab(t);"*" 760 goto 770 765 print h;tab(z);"+";tab(t);"*" 770 next i 775 goto 851 800 rem - plot f(x)=0 at edge of graph 810 for i = 0 to n 815 let h = x1+(x2-x1)*i/n 825 let t = 15+((fna(h))-l1)/s 830 if i/5-int(i/5) = 0 then 845 835 print tab(14);"i";tab(t);"*" 840 goto 850 845 print h;tab(14);"+";tab(t);"*" 850 next i 851 print tab(8);"-f(x)<-+---------+---------+---------+"; 852 print "---------+---------+->f(x)" 853 print tab(14);l1;tab(24);l1+10*s;tab(34);l1+20*s; 854 print tab(44);l1+30*s;tab(54);l1+40*s;tab(64);l1+50*s 860 gosub 1300 865 print "exit from graphfunction" 870 end 1300 rem - line space subroutine 1310 for i = 1 to 4 1320 print 1330 if i <> 2 then 1380 1350 for j = 1 to 72 1360 print "-"; 1370 next j 1380 next i 1390 return 1500 rem constants used :-a,b,c,c1,d,e,e2,g,h,k,l1,l2,m1,m2,n,p, a$,b$ 1505 rem constants used :-s,t,x,x1,x2,x3,y,y1,y2,z i&j used for loops |