%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% yu2.m
% A simple m-file for yu trace for thin lenses
% This program is used for both axial and parallel rays.
% Last modified: Mar 2018
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Power of the surfaces P = 1/f. for OBJ and IMA planes P=0.
P = [0   1/100  1/25  0];

% Thickness (distance) between surfaces
t = [60 20+12 80];

% Number of surfaces
N = length(t);

% Initial values (height and angle)
% of axial ray
y(1) = 0.0; % for calculation of magnification change this
u(1) = 0.1;
% of paralel ray
yy(1)= 1.0;
uu(1)= 0.0; 

% yu trace
for k=1:N
   % yu trace of axial ray
   y(k+1) = y(k) + u(k)*t(k);
   u(k+1) = u(k) - y(k+1)*P(k+1);
   % yu trace of paralel ray
   yy(k+1) = yy(k) + uu(k)*t(k);
   uu(k+1) = uu(k) - yy(k+1)*P(k+1);
end

% Print results to the user screen
YU = [y' u']
effl = -yy(1)/uu(end);
qf = -y(end-1)/u(end-1);
m = y(end)/y(1);

fprintf('Number of Surfaces     : %d\n', N+1);
fprintf('Effective focal length : %f\n', effl);
fprintf('Quick Focus            : %f\n', qf);
fprintf('Magnification          : %f\n', m);
