' nm1lib.bas - jackord@kw.igs.net - revised 2 Feb 08 - Liberty Basic v4.02 ' string of length L, clamped at both ends ' "Pluck" and "Pulse" initial displacements ' motion generated by superposition of waves of wavelength 2L ' travelling in opposite directions ' y(L/4) is plotted versus time ' Initialize Window nomainwin button#1, "Pluck", [p1], UL, 5, 5, 50, 20 button#1, "Pulse", [p2], UL, 60, 5, 50, 20 button#1, "Motion", [p3], UL, 115, 5, 50, 20 WindowWidth=543 ' Pixel Scale 0-525 WindowHeight=268 ' Pixel Scale 0-230 UpperLeftX=10: UpperLeftY=10 open "Travelling Wave Superposition" for graphics_nsb as #1 #1 "trapclose [quit]" n=384: dim y(2*n+1): dim t(n+1): dim z(n+1) #1 "down ; line 393 129 521 129" kk=0: plt=0 [waitHere] wait [p1] ' Pluck kk=1: goto [plot] [p2] ' Pulse kk=2: goto [plot] [p3] ' Motion if kk>0 then plt=1: goto [plot] goto [waitHere] [plot] redim y(2*n+1) #1 "cls ; color black ; line 393 129 521 129" ' y(L/4) plot axis #1 "line 3 109 3 149 ; line 388 109 388 149" if kk=1 then ' Initialize pluck for i=0 to n/2 y(i)=i/4: y(n-i)=y(i) next i else ' Initialize pulse for i=3*n/8 to n/2 y(i)=i-3*n/8: y(n-i)=y(i) next i end if for i=0 to n y(n+i)=0-y(i) next i jt=0: z(0)=129: z(n)=z(0): t(0)=z(0) while jt=0 or plt=1 ' Main loop #1 "color blue ; backcolor red ; rule xor" for i=1 to n ' Plot n segments ia=i+jt: while ia>2*n: ia=ia-2*n: wend ib=i-jt: while ib<0: ib=ib+2*n: wend t(i)=129-y(ia)-y(ib) if jt>0 then #1 "line "; i+3; " "; z(i-1); " "; i+4; " "; z(i) if i=n/4 then #1 "color red ; circlefilled 6 ; circle 6 ; color blue" end if #1 "line "; i+3; " "; t(i-1); " "; i+4; " "; t(i) z(i-1)=t(i-1) if i=n/4 then #1 "color red ; circlefilled 6 ; circle 6 ; color blue" next i x2=393+jt/6: y2=z(n/4) ' Plot y(L/4) vs t if jt>0 then #1 "color red ; rule over; line "; x1; " "; y1; " "; x2; " "; y2 x1=x2: y1=y2 scan jt=jt+1: if jt=2*n+1 then plt=0: kk=0 #1 "discard" wend goto [waitHere] [quit] close #1 end