% coilgun.m % a model for the basic vertical launch coilgun % created and written by Glen E. Gardner, Jr. % glen.gardner@verizon.net % calculates a single coil count=count+1 % the average velocity at the end of the coils (meters per second) v=sqrt((i*2*dKE)/m) % the change in velocity dv=v-vo % store it for use on the next iteratioon vo=v % the average time to travel through all the coils.(seconds) t=(l1*i)/(0.5*v) % the change in time dt=t-to % store it for the next iteration to=t % average acceleration through this coil only (meters per second per second) da=dv/dt % the average force exerted by this coil (Newtons) F=(m*da) % average work done by this coil(Joules) W=F*l1 % total work done (Joules) W=(F*l1)*i % calculate the desired resonant frequency of the coil f=1/dt % calculate the inductance of the coil L=((1/f)/(2*pi))^2/dC