function GraphicalMethod()
%   This function graphs the array factor and the radiation pattern for a 5-element
%   dipole antenna.  It requires a second Matlab file, polar3.m.
%   In this example, the 5 elements are spaced lambda/2 apart and the steering
%   angle is 40°.



% ****************  USER-EDITABLE SECTION  ********************************************

N=5; f=98e6; c=299792458; lambda=c/f; theta=pi/2; Io=1; d=lambda/2;        % constants
w=2*pi*f; k=w/c; psi=40*pi/180; n=5;                                       % constants
                                            % the expression to be plotted, x in radians
expression1 = 'AF=abs((sin(n*x/2))/sin(x/2)); y=AF;';  
expression2 = 'phi=t; Psi=-k*d*sin(psi); u=k*d*sin(phi)+Psi; AF=abs(exp(j*(n-1)/2*u)*(sin(n*u/2))/sin(u/2)); rho=AF;';  
PlotWindowSize = [1700,1100];               % plot window size in pixels
Domain = pi*[-2 2/5 2]; Range = n*[0 .1 1.05];    % domain & range [min spacing max]
Resolution = 1000;                          % number of X-values to plot
Line_Width = 2;                             % width of the plot line
% TEXT SETTINGS  \itx makes an italic x, \Lambda \lambda make uppercase and lowercase
%     lambdas.
tTXT = 'Radiation Pattern';       % Title
xTXT = '\itu';                              % the X-axis label
yTXT = 'Magnitude';                         % the Y-axis label
xLabels = '-2 pi|-8/5 pi|-6/5 pi|-4/5 pi|-2/5 pi|0|2/5 pi|4/5 pi|6/5 pi|8/5 pi|2 pi';
Fnt  = [20 16 16];                          % fontsize for [title labels grid#s]



% ****************  EVALUATE THE EXPRESSION  ****************************************

X=[]; Y=[]; T=[]; Rho=[]; x=Domain(1);                    % initialize variables
while x < Domain(3),                        % fill the matrices
   eval(expression1);                       % evaluate the expression
	X = [X,x]; Y = [Y,y];                    % form matrices for X and Y values
	x = x+((Domain(3)-Domain(1))/Resolution);% controls the resolution of the plot
end                                         % end of "while" statements
t=0;
while t < 2*pi
   eval(expression2);
   T = [T,t]; Rho = [Rho,rho];
   t = t+2*pi/Resolution;
end

% ****************  PLOT THE EXPRESSION  ********************************************

figure('Position',[-10 -110 PlotWindowSize(1) PlotWindowSize(2)])
plot(X,Y,'LineWidth',Line_Width);           % create plot, set linewidth
                                            
% ****************  APPLY TEXT AND GRID SETTINGS  ***********************************

Xtk=[Domain(1)]; Unit=Domain(1)+Domain(2);  % x-axis tick marks/grid lines
while Unit <= Domain(3)
   Xtk = [Xtk,Unit]; Unit=Unit+Domain(2);
end
cnt=1; Ytk=[Range(1)];                      % y-axis tick marks/grid lines
while cnt*Range(2)<=Range(3)-Range(1)
   Ytk = [Ytk,Ytk(cnt)+Range(2)]; cnt=cnt+1;
end

set(gca,'FontSize',Fnt(3)), grid on         % set grid fontsize, make the grid visible
set(gca,'Xtick',Xtk); set(gca,'Ytick',Ytk); % set the X&Y tick marks/grid lines
xlimits = [Domain(1) Domain(3)];            % set the X axis limits to the range specified
set(gca,'Xlim',xlimits);                    % apply the specified range
ylimits = [Range(1) Range(3)];              % set the Y axis limits to the range specified
set(gca,'Ylim',ylimits);                    % apply the specified range
set(gca,'XTickLabel',xLabels)   % label the x-axis
title(tTXT, 'FontSize',Fnt(1), 'Color',[0 0 0])
xlabel(xTXT,'FontSize',Fnt(2), 'Color',[0 0 0])
ylabel(yTXT,'FontSize',Fnt(2), 'Color',[0 0 0])

% ****************  THE POLAR PLOT  ****************************************

figure('Position',[10 -120 PlotWindowSize(2) PlotWindowSize(2)])
polar3(T,Rho*1.00001,Line_Width+1);          % variables, linewidth, linestyle to plot
set(gca,'FontSize',16)
grid on                                     % make the grid visible
title(tTXT,'FontSize',18,'Color',[0 0 0])   % add a title to the plot

Angle = Psi*180/pi
Pies = Psi/pi
