                %%% SYMPLECTICITY - SIMPLE EXAMPLES - Written by S. Memarzadeh and S. Bernal, 7/6/2016 %%%
clc
syms L f1 theta k0 real

J = [0 1; -1 0]; % Antisymmetric Matrix

D = [1 L; 0 1]; % Matrix for Drift of length L

J1 = J^2*J' % J is symplectic

D1 = D * J * D'  % Drift is Symplectic

M1 = [1 0 ; -1/f1 1]; % Thin Lens Transformation

Y1 = M1 * J * M1' % Thin Lens is Sympletic

M2x = [cos(theta) k0^-1 * sin(theta); % F-Quadrupole Matrix
    -k0*sin(theta) cos(theta)]

Y2 = M2x * J * M2x' % Symplectic!
simplify(Y2)

M2y = [cosh(theta) k0^-1*sinh(theta); % D-Quadrupole Matrix
    k0*sinh(theta) cosh(theta)]

Y3 = M2y * J * M2y' % Symplectic!
simplify(Y3)

M = M1 * D * M1 % Thin-lens doublet is a thick lens (see Chapter 1)

Y4 = M * J * M' % Thin-doublet is non-symplectic,unless spacing L=0
