! PHYS 2P20 - 2020-21 Lab3: damped harmonic oscillator ! ! By Edward Sternin ! 2020.09.29 read damped.txt t\1 ay\3 clear defaults set xlabel `Time, s' ylabel `Acceleration, m/s<^>2' graph t,ay scales 0 4 4 0 0 0 clear\noreplot replot Pi=asin(1.0)*2.0 scalar\vary g,a,w,t0 g=9.8 w=2*Pi/0.5 t0=0.45 a=6 inquire `Initial fit to g+a*sin[w*(t-t0)]: {g a w t0} = {'//rchar(g)//` '//rchar(a)//` '//rchar(w)//` '//rchar(t0)//`} ' g a w t0 scales 0 max(t) 0 0 0 0 clear\noreplot replot t2=t0 i=0 loop: t1=t2 t2=t1+4*Pi/w if (t2>max(t)) then goto done tt=t[iclose(t,t1):iclose(t,t2)] aa=ay[iclose(t,t1):iclose(t,t2)] fit\e2 aa=g+a*sin(w*(tt-t0)) set color -(mod(i,17)+2) graph\overlay tt,g+a*sin(w*(tt-t0)) i=i+1 tf[i]=0.5*(t1+t2) f[i]=w df[i]=fit$e2[3] goto loop done: list tf,f,df terminal clear defaults set xlabel `Time, s' ylabel `, rad/s' pchar -17 %xloweraxis 15 %yloweraxis 12 graph tf,f,df