see this complete code here
clc
clear all;
close all;
%----------- Common Parameters for both approaches ------------
N = input('Enter the value of N --------> ');
N = round(N); % convert to integer
if(mod(N,2) == 0)
M = N/2;
else
M = (N-1)/2;
end
lambda = 50;
samples = 'odd'; % possible values can be 'odd' or 'evn'
k = 2*pi/lambda;
if(samples == 'odd')
m = -M : M;
else
m = -M : M;
index = find(m == 0);
m(index) = [];
end
[row, col] = size(m);
bm = [zeros(1,2) ones(1,col-4) zeros(1,2)];
%--------------- Line Source Parameters & Code ----------------
d = lambda/2;
length = N*d;
kk = 1;
sum = 0;
jj = 1;
[row, col] = size(m);
for ii = 1 : col
mm = m(ii);
yy = cos_theta_m(mm, lambda, length, samples);
zz=z_m(mm,d,samples);
sum = sum + (bm(jj)*exp(-j*k*zz*yy));
jj = jj + 1;
AF(kk) = sum;
kk = kk + 1;
end
kk
%---------------------------- Lets plot the results -----------
figure; grid; hold on;
plot(-M:M, abs(AF), 'r');
xlabel('source psition z');
ylabel('Normalized current');
title('current distribution for linear array');
%----------------------------------------------------------------
run for N=123, yeilds