% this plots rays through a set of lenses using ABCD matrices % this file uses the functions % free_space.m % lens.m global xx yy a1 clf hold 'on' ho=1; %the object height %lens focal lengths f1=50; f2=16.67; %spacings between elements xo=50; x1=25; x2=20; (xo*f1)/(xo-f1) %the position/focal length array xf=[xo,f1,x1,f2,x2]; %the type of each element in the array type=['x', 'f', 'x', 'f', 'x']; lens_h=2; % this is the height of the line plotted for each lens %the rays to plot aa1=[ho;0]; %ray 1 aa2=[ho;-.01]; %ray 2 %ray 1 a1=aa1; xx=0; yy=a1(1); for lp=1:length(xf) if type(lp) == 'x' free_space(xf(lp)) elseif type(lp) == 'f' lens(xf(lp)) plot([xx(end), xx(end)], [-lens_h, lens_h],'k') end end plot(xx,yy) plot([0, max(xx)], [0,0],'k:') %ray 2 a1=aa2; xx=0; yy=a1(1); for lp=1:length(xf) if type(lp) == 'x' free_space(xf(lp)) elseif type(lp) == 'f' lens(xf(lp)) end end plot(xx,yy) hold 'off'