' h3alib.bas - jackord@kw.igs.net - revised 10 Sep 02 - Liberty Basic v3.01 ' integration algorithms for bouncing ball ' Initialize Window nomainwin button#1, "Plot", [plot], UL, 10, 10, 50, 20 WindowWidth=510 ' pixel scale 0-500 WindowHeight=389 ' pixel scale 0-360 UpperLeftX=50: UpperLeftY=100 open "Integration Algorithms" for graphics_nsb as #1 #1 "trapclose [quit]" gosub [pin] [waitHere] wait [plot] gosub [pin] gr=9.8: h=4.9: xa=h/8: xb=7*h/8: dx=h/200 va=(2*gr*(h-xa))^.5: vb=(2*gr*(h-xb))^.5: vbar=(va+vb)/2 #1 "color blue" #1 "place "; 88+int(80*xa); " "; 312-int(750/va) for i=1 to 200 x=i*dx: v=(2*gr*(h-x))^.5 #1 "goto "; 88+int(80*x); " "; 312-int(750/v) if v<=2.5 then i=200 next i #1 "color black" x1=88+int(80*xb): y1=312-int(750/vb) #1 "line "; x1; " 312 "; x1; " "; y1 x1=88+int(80*xa): y1=312-int(750/vbar) #1 "line "; x1; " 312 "; x1; " "; y1 #1 "color green" y1=312-int(750/va): x2=88+int(80*xb): y2=312-int(750/vb) #1 "line "; x1; " "; y1; " "; x2; " "; y2 #1 "color darkpink" y1=312-int(750/vbar) #1 "line "; x1; " "; y1; " "; x2; " "; y1 #1 "color red" y1=312-int(750/(2*gr*(h-xa/2-xb/2))^.5) #1 "line "; x1; " "; y1; " "; x2; " "; y1 #1 "color black" n=20: gosub [rect]: s1=s: n=40: gosub [rect]: s2=s: s3=s2+(s2-s1)/3 s1$=left$(str$(s1), 8): s2$=left$(str$(s2), 8): s3$=left$(str$(s3), 8) #1 "place 100 32" #1 "\Rect: T(20) = "; s1$; " T(40) = "; s2$; " T = "; s3$ #1 "place 210 80" #1 "\Analytic: T = Tvbar = 1" goto [waitHere] [pin] #1 "cls": #1 "down": #1 "color black" #1 "place 88 12": #1 "box 488 312" #1 "place 85 332": #1 "\0" #1 "place 485 332": #1 "\5" #1 "place 268 344": #1 "\x (m)" #1 "place 72 318": #1 "\0" #1 "place 66 18": #1 "\0.4" #1 "place 16 133": #1 "\1/V(x)" #1 "place 24 203": #1 "\(s/m)" return [rect] s=0: dx=h/n for i=1 to n if i=0 or i=n then c=.5 else c=1 x=(i-.5)*dx: s=s+1/(2*gr*(h-x))^.5 next i s=s*dx return [quit] close #1 end