function ans=free_space(x) %this function uses ABCD matrices to perform free space propagation global xx yy a1 M=[1,x;0,1]; a2=M*a1; xx=[xx,xx(end)+x]; yy=[yy,a2(1)]; a1=a2;