' nm3lib.bas - jackord@kw.igs.net - revised 17 Feb 08 - Liberty Basic v4.02 ' string of length 8d, clamped at both ends ' equal point masses at intervals of d ' finite and infinite Fourier Sine Series representations of ' "pluck" and "pulse" initial displacements ' Initialize Window nomainwin button#1, "Pluck FFSS", [p1], UL, 10, 5, 90, 20 button#1, "Pulse FFSS", [p2], UL, 105, 5, 90, 20 button#1, "Pluck FSS", [p3], UL, 200, 5, 90, 20 button#1, "Pulse FSS", [p4], UL, 295, 5, 90, 20 WindowWidth=414 ' Pixel Scale 0-396 WindowHeight=278 ' Pixel Scale 0-240 UpperLeftX=10: UpperLeftY=10 open "Fourier Series" for graphics_nsb as #1 #1 "down ; backcolor blue ; trapclose [quit]" dim y(9): dim b(9) n=8: pi=4*atn(1) [waitHere] wait [p1] kk=1: ff=1: goto [series] [p2] kk=2: ff=1: goto [series] [p3] kk=1: ff=2: goto [series] [p4] kk=2: ff=2: goto [series] [series] if kk=1 then ' Initialize pluck for i=0 to n/2 y(i)=40*i: y(n-i)=y(i) next i for i=1 to n-1 step 2 ' Pluck FSS coeffts b(i)=80*(4/pi/i)^2*sin(i*pi/2) next i end if if kk=2 then ' Initialize pulse for i=0 to n y(i)=0 next i y(4)=160 for i=1 to n-1 step 2 ' Pulse FSS coeffts b(i)=80*(8/pi/i)^2*(sin(pi*i/2)-sin(pi*i*3/8)) next i end if if ff=1 then for i=1 to n-1 step 2 ' FFSS coeffts b(i)=0 for j=1 to n-1 b(i)=b(i)+2*y(j)/n*sin(pi*i*j/n) next j next i end if #1 "cls ; color blue ; place 6 195" for i=0 to n ' Draw displacement #1 "goto "; 6+48*i; " "; 195-y(i) #1 "rule xor ; circlefilled 6 ; circle 6 ; rule over" next i #1 "color green" for i=1 to n-1 step 2 ' Draw components #1 "place 6 195" for j=1 to 48*n #1 "goto "; 6+j; " "; 195-int(b(i)*sin(pi*i*j/n/48)) next j next i #1 "color red ; place 6 195" for j=1 to 48*n ' Draw sum z=0 for i=1 to n-1 step 2 z=z+b(i)*sin(pi*i*j/n/48) next i #1 "goto "; 6+j; " "; 195-int(z) next j #1 "discard" goto [waitHere] [quit] close #1 end