% Book: Laser Electronics by Verdeyen
% Problem: Chapter 3 problem 20
% Script Author: meg noah meg_noah@student.uml.edu
function Lasers_Ch3_Pr20
figure(1);true;
axis([-2 2 -2 2]);
[X,Y] = meshgrid(-2:.15:2);
R2 = X.^2+Y.^2
xmode = 2; % edit the xmode and ymode
ymode = 3; % to get different patterns
switch xmode
   case 0
      Hx = 1.0;
   case 1
      Hx = 2.0*X;
   case 2
      Hx = (4.0*X.^2-2.0);
   case 3
      Hx = (8.0*X.^3-12.0*X);
   otherwise
      Hx = 1.0;
end 
switch ymode
   case 0
      Hy = 1.0;
   case 1
      Hy = 2.0*Y;
   case 2
      Hy = (4.0*Y.^2-2.0);
   case 3
      Hy = (8.0*Y.^3-12.0*Y);
   otherwise
      Hy = 1.0;
end 
Umn = Hx.*Hy.*exp(-R2);
Umn = Umn.^2
contourf(X,Y,Umn,12)
%surface(X,Y,Umn)
%view(-35,55)
hold on
colormap hsv
grid off
hold off
