%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% zoomlens.m
% This is simple program for afocal variable zoom lens
% design. System contains three thin lenses with
% focal lengths f1,f2,f3. Program outputs distance
% between lenses (namely, total length of the system)
% and corresponding magnification.
%
% Author: Ahmet Bingül
%
% Mar 2019
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear; clc;
% focal lengths
f1 =  300; f2 = -200; f3 =  150;
% initial ray height and slope=0
y0 = 1; u0 = 0;
% distance between initial ray and lens 1
t0 = 10; % arbitrary
% distance between lens 1 and 2.
t1 = 250;

% Calculations (y-u trace)
y1 = y0 + u0.*t0;
u1 = u0 - y1./f1;
y2 = y1 + u1.*t1;
u2 = u1 - y2./f2;

% Final ray height
y3 = u2.*f3;
% distance between lens 2 and 3
t2 = (y3 - y2)./u2;

% magnification
m  = abs(y0./y3);

% to print
[t1' t2' (t1+t2)' m']
